我在Kivy ScreenManager中设置了一个屏幕(myScreen只是一个继承屏幕的类)
class firstScreen(myScreen):
def __init__(self,**kwargs):
super(firstScreen, self).__init__(**kwargs)
self.name = "first"
self.add_widget(Button(on_release = switchScreens("second")))
我还设置了第二个屏幕:
class secondScreen(myScreen):
def __init__(self,**kwargs):
super(secondScreen, self).__init__(**kwargs)
self.name = "second"
然后我设置了我的ScreenManager:
sm = ScreenManager()
sm.add_widget(firstScreen())
sm.add_widget(secondScreen())
以下是switchScreens的代码:
def switchScreens(next):
sm.current = next
当我运行sm时,我收到以下错误:
kivy.uix.screenmanager.ScreenManagerException:No screen with name" second"。
这对我来说似乎不对,因为我将secondScreen()添加到sm,名称为" second"。
如何让firstScreen上的按钮正确地将应用程序发送到secondScreen?
答案 0 :(得分:1)
在此处定义名称,而不是屏幕类:
sm = ScreenManager()
sm.add_widget(firstScreen())
sm.add_widget(secondScreen())
应该是:
sm = ScreenManager()
sm.add_widget(firstScreen(name="first"))
sm.add_widget(secondScreen(name="second"))