我正在使用Kivy Screen Manager,我试图在标签中显示当前屏幕的名称。但是当我用下面的标签运行应用程序时,我的应用程序立即崩溃。如何在标签内显示当前的屏幕名称?
MyScreenManager:
LoginScreen:
MenuScreen:
SettingsScreen:
LogoutScreen:
<[email protected]>:
name: 'menu'
BoxLayout:
orientation: 'vertical'
Header:
Toolbar:
BoxLayout:
<[email protected]>:
orientation: 'vertical'
height: 100
size_hint_x: 1
size_hint_y: None
Label:
text: 'Dealer App'
color: 0.212, 0.486, 0.169, 1
font_size: 48
Label:
height: 30
text_size: self.width*.9, None
halign: 'right'
size_hint_y: None
text: app.root.current_screen
font_size: 16
color: 0, 0, 1, 1
此标签不用于第一个屏幕,但当我启动应用程序时出现以下错误。
...
89: halign: 'right'
90: size_hint_y: None
>> 91: text: app.root.current_screen
92: font_size: 16
93: color: 0, 0, 1, 1
...
AttributeError: 'NoneType' object has no attribute 'bind'
我想使用kv语言添加此标签。第91行是否存在问题,还是因为在运行这段代码时尚未创建当前屏幕?如果是后者,如何让它等到当前屏幕存在之后?
即使你想使用kv,如果在纯python中编写这个布局,你的代码是否运行? – barrios