对Kivy来说非常陌生,并且尝试动态地添加小部件,但是尽管我遵循了所有的示例,我还是无法使用我的。在
我的.kv文件是。。。在
ScreenManager:
MainScreen:
LoginScreen:
<MainScreen>:
name: 'MainScreen'
id: ms
BoxLayout:
id: rc_display
orientation: "vertical"
padding: 10
spacing: 10
Label:
id: ms_label1
text: 'Oh Hell Yeah'
<LoginScreen>:
name: 'LoginScreen'
id: ls
Button:
on_release: app.root.current
text: 'Click to Login'
font_size: 20
我的python代码是。。。在
^{pr2}$当我运行以上我得到以下错误。。。在
File "*pathtoFile*/StagePlanning.py", line 12, in on_pre_enter
show_view = self.ids.rc_display
File "kivy\properties.pyx", line 839, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:12654)
AttributeError: 'super' object has no attribute '__getattr__'
如果我将这些小部件直接添加到屏幕对象中,它们会显示,但会相互叠加。只有当我尝试引用id时才会出错。在
我甚至在控制台上打印了id的列表,它们如预期的那样在那里。在
问题是由于
on_pre_enter
事件是在添加BoxLayout
之前完成的,因此它不存在,一个可能的解决方案是使用Clock
:另一个选项是在BoxLayout构造函数中定义它:
*.py
^{pr2}$*.kv
相关问题 更多 >
编程相关推荐