我正在使用屏幕管理器,并且想在不使用 .kv 文件的情况下将小部件添加到屏幕子类。
class MainMenu(Screen):
def __init__(self, **kwargs):
gLayout = GridLayout()
gLayout.add_widget(Button(text = 'test'))
class Sis(App):
def build(self):
root = ScreenManager()
root.add_widget(MainMenu(name = 'mainMenu'))
root.current = 'mainMenu'
return root
Sis().run()
当我尝试运行上面的代码时,我得到(pygame parachute) Segmentation Fault
.
如果我在 .kv 文件中创建布局,它可以正常工作。
我试过摆弄on_pre_enter
,on_enter
但我很确定我用错了。
任何帮助表示赞赏。