提问人:VIGNESH C 提问时间:5/1/2023 更新时间:5/1/2023 访问量:34
KIVYMD 中堆叠类的属性名称无效
Invalid property name for stacked classes in KIVYMD
问:
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.core.window import Window
from kivy.properties import ObjectProperty
from kivymd.uix.scrollview import MDScrollView
Window.clearcolor = (0, 0.6, 0.1, 1.0)
Window.size = (300, 500)
KV='''
#:import Snackbar kivymd.uix.snackbar.Snackbar
#signin screen with options as PATIENT, DOCTOR or GUEST
<HomeScreen>:
name: "home_screen"
MDScreen:
FitImage:
source: 'background_img.jpg'
MDLabel:
text:' Create an account! | SIGN-IN '
font_style:'H5'
size_hint_y:None
bold:True
height:self.texture_size[1]
halign:'center'
pos_hint: {"center_x": .5, "center_y": .7}
MDIconButton:
text:'PATIENT'
icon:'account'
pos_hint: {"center_x": .4, "center_y": .4}
width:100
on_press:
root.manager.current = 'p_login_screen'
root.manager.transition.direction = "left"
Snackbar(text="Fill in the above details to continue...").open()
MDIconButton:
text:'DOCTOR'
icon:'doctor'
pos_hint: {"center_x": .6, "center_y": .4}
width:100
on_press:
root.manager.current = 'd_login_screen'
root.manager.transition.direction = "left"
Snackbar(text="Fill in the above details to continue...").open()
MDLabel:
text:'or'
font_style:'Subtitle2'
size_hint_y:None
bold:True
height:self.texture_size[1]
halign:'center'
pos_hint: {"center_x": .5, "center_y": .3}
MDTextButton:
text:'Login as guest'
font_style:'Caption'
icon:'guest'
pos_hint: {"center_x": .5, "center_y": .2}
width:100
on_press: root.manager.current = 'main.py'
on_release: Snackbar(text="You have created account successfully!").open()
MDLabel:
text:'____________________________'
font_style:'Subtitle2'
size_hint_y:None
bold:True
height:self.texture_size[1]
halign:'center'
pos_hint: {"center_x": .5, "center_y": .156}
MDTextButton:
text:'Already a member?'
font_style:'Caption'
pos_hint: {"center_x": .5, "center_y": .1}
width:100
on_press: root.manager.current = 'main.py'
on_release: Snackbar(text="You have created account successfully!").open()
#Patients login pages with various details
<P_login_Screen>
name: "p_login_screen"
MDScreen:
MDLabel:
text:'Create a patient account!'
font_style:'H5'
size_hint_y:None
bold:True
height:self.texture_size[1]
halign:'center'
pos_hint: {"center_x": .5, "center_y": .85}
MDTextField:
hint_text: "Enter name:"
multiline:False
required: True
max_text_length: 25
size_hint_x:None
line_color_focus: 0, 1, 0, 1
mode: "round"
icon_left: "account"
icon_right_color: app.theme_cls.primary_color
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .7}
width:300
MDTextField:
hint_text: "Enter Gender:"
multiline:False
required: True
line_color_focus: 0,1,0, 1
mode: "round"
size_hint_x:None
icon_left: "eye"
icon_right_color: app.theme_cls.primary_color
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .6}
width:300
MDTextField:
width:300
hint_text: "Enter Age:"
multiline:False
max_text_length: 2
required: True
size_hint_x:None
line_color_focus: 0,1,0, 1
mode: "round"
icon_left: "help"
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .5}
MDTextField:
hint_text: "Enter Phone number:"
multiline:False
max_text_length: 10
required: True
size_hint_x:None
line_color_focus: 0,1,0, 1
mode: "round"
icon_left: "phone"
icon_right_color: app.theme_cls.primary_color
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .4}
width:300
MDTextField:
hint_text: "Enter E-Mail:"
multiline:False
helper_text: "Enter valid email"
required: True
line_color_focus: 0,1,0, 1
mode: "round"
size_hint_x:None
icon_left: "gmail"
icon_right_color: app.theme_cls.primary_color
validator: "email"
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .3}
width:300
MDRectangleFlatButton:
text:'Sumbit!'
pos_hint: {"center_x": .5, "center_y": .2}
width:300
on_press: root.manager.current = 'main.py'
on_release: Snackbar(text="You have created account successfully!").open()
MDIconButton:
icon:'chevron-left'
pos_hint: {"center_x": .125, "center_y": .075}
width:100
on_press:
root.manager.current = 'home_screen'
root.manager.transition.direction = "right"
<D_login_Screen>
name: "d_login_screen"
MDScreen:
MDLabel:
text:'Create a doctor account!'
font_style:'H5'
size_hint_y:None
bold:True
height:self.texture_size[1]
halign:'center'
pos_hint: {"center_x": .5, "center_y": .85}
MDTextField:
hint_text: "Enter name:"
multiline:False
required: True
max_text_length: 25
size_hint_x:None
line_color_focus: 0, 1, 0, 1
mode: "round"
icon_left: "account"
icon_right_color: app.theme_cls.primary_color
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .7}
width:300
MDTextField:
hint_text: "Enter Gender:"
multiline:False
required: True
line_color_focus: 0,1,0, 1
mode: "round"
size_hint_x:None
icon_left: "eye"
icon_right_color: app.theme_cls.primary_color
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .6}
width:300
MDTextField:
width:300
hint_text: "Enter Age:"
multiline:False
max_text_length: 2
required: True
size_hint_x:None
line_color_focus: 0,1,0, 1
mode: "round"
icon_left: "help"
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .5}
MDTextField:
hint_text: "Enter Phone number:"
multiline:False
max_text_length: 10
required: True
size_hint_x:None
line_color_focus: 0,1,0, 1
mode: "round"
icon_left: "phone"
icon_right_color: app.theme_cls.primary_color
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .4}
width:300
MDTextField:
hint_text: "Enter E-Mail:"
multiline:False
helper_text: "Enter valid email"
required: True
line_color_focus: 0,1,0, 1
mode: "round"
size_hint_x:None
icon_left: "gmail"
icon_right_color: app.theme_cls.primary_color
validator: "email"
text_color_focus:1,0.5,1,1
pos_hint: {"center_x": .5, "center_y": .3}
width:300
MDRectangleFlatButton:
text:'Sumbit!'
pos_hint: {"center_x": .5, "center_y": .2}
width:300
on_press: root.manager.current = 'main.py'
on_release: Snackbar(text="You have created account successfully!").open()
MDIconButton:
icon:'chevron-left'
pos_hint: {"center_x": .125, "center_y": .075}
width:100
on_press:
root.manager.current = 'home_screen'
root.manager.transition.direction = "right"
<MAINScreen>
name: "main.py"
<ContentNavigationDrawer>:
MDList:
spacing:'8dp'
padding:'8dp'
MDLabel:
text:'Health CheckUp App'
font_style:'Subtitle1'
size_hint_y:None
bold:True
height:self.texture_size[1]
MDLabel:
text:'Created by VIGNESH.C'
font_style:'Caption'
size_hint_y:None
height:self.texture_size[1]
OneLineAvatarIconListItem:
text: "Home"
on_press:
root.nav_drawer.set_state("close")
root.screen_manager.current = "scr 1"
IconLeftWidget:
icon: "home"
on_press:
root.screen_manager.current = "scr 1"
OneLineAvatarIconListItem:
text: "Settings"
on_press:
root.nav_drawer.set_state("close")
root.screen_manager.current = "scr 2"
IconLeftWidget:
icon: "widgets"
on_press:
root.screen_manager.current = "scr 2"
MDScreen:
MDTopAppBar:
pos_hint: {"top": 1}
elevation: 4
title: "Health CheckUp App"
left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
right_action_items: [["account-circle", lambda x: nav_drawer.set_state("open")]]
MDNavigationLayout:
MDScreenManager:
id: screen_manager
MDScreen:
name: "scr 1"
MDLabel:
text:'Dashboards'
font_name:"Comic"
color:1,.5,1,1
font_size:30
pos_hint:{'center_x':.2,'center_y':.7}
texture_size: self.size
text_size: self.size
MDFloatingActionButtonSpeedDial:
icon:'phone'
data:app.data
root_button_anim:True
hint_animation:True
bg_color_root_button:"red"
bg_color_stack_button:"green"
bg_hint_color:'grey'
color_icon_stack_button:'white'
label_text_color: "white"
MDScreen:
name: "scr 2"
MDLabel:
text: "Screen 2"
halign: "center"
MDNavigationDrawer:
id: nav_drawer
radius: (0, 16, 16, 0)
ContentNavigationDrawer:
screen_manager: screen_manager
nav_drawer: nav_drawer
<RootWidget>:
HomeScreen:
name: "home_screen"
D_login_Screen:
name:'d_login_screen'
P_login_Screen:
name: "p_login_screen"
MAINScreen:
name:'main.py'
ContentNavigationDrawer:
name:'cont'
'''
class HomeScreen(Screen):
pass
class P_login_Screen(Screen):
pass
class D_login_Screen(Screen):
pass
class MAINScreen(Screen):
pass
class ContentNavigationDrawer(MDScrollView):
screen_manager = ObjectProperty()
nav_drawer = ObjectProperty()
class RootWidget(ScreenManager):
pass
Builder.load_string(KV)
class MainApp(MDApp):
data= {
'Ambulance':'ambulance',
'Doctor':'doctor',
"Home":'home',
}
def build(self):
self.title = "Health CheckUp App"
return RootWidget()
if __name__ == "__main__":
MainApp().run()
我收到此错误: >> 249: :
250:251:MDList:
...
属性名称无效
如何更正我的代码????
无错误页面,带有干净的动画和小部件
需要的是,当我单击“以访客身份登录”时,我应该得到一个包含所有小部件的页面,当我单击左上角的菜单按钮时,我应该得到一个带有屏幕过渡的列表。
答:
0赞
John Anderson
5/1/2023
#1
在 中,您有:KV
<MAINScreen>
name: "main.py"
<ContentNavigationDrawer>:
这是一个语法错误。不能将规则放在另一个规则中。也许你的意思是:<ContentNavigationDrawer>
<MAINScreen>
name: "main.py"
ContentNavigationDrawer:
评论