我的代码有问题,该应用程序似乎可以运行,但是没有显示内容。 我不知道为什么它没有显示内容。 这是我的代码:
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
class entry(Screen):
pass
class secret(Screen):
pass
SM = ScreenManager()
SM.add_widget(entry(name="entry"))
SM.add_widget(secret(name="secret"))
class ScreenApp(App):
def build(self):
return SM
if __name__ == "__main__":
ScreenApp().run()
和我的kv文件
<entry>
GridLayout:
cols: 3
Label:
text: "Enter the password"
TextInput:
id: password
multiline: False
Button:
text: "Enter"
on_press: root.manager.current = "secret" if password.text == "love" else "Screen 1"
<secret>
GridLayout:
cols: 1
Label:
text: "You have reached my secret"
Button:
text: "Back"
on_press: root.manager.current = "entry"
我做错了什么? python或kv文件有问题吗?
答案 0 :(得分:0)
您必须这样做:
class ScreenApp(App):
def build(self):
SM = ScreenManager()
SM.add_widget(entry(name="entry"))
SM.add_widget(secret(name="secret"))
SM.current = 'entry'
return SM
如果您没有在文本框中输入“ love”(因为它需要Screen1,但您尚未定义Screen1),则会出现错误