我是 Kivy 的新手,遇到了问题。我有“MainPanel”类,它包含四个类“导航”、“图像”、“配置”和“信息”。我想要的是当在“导航”类中按下按钮时,然后在“信息”类中使用屏幕管理器更改当前屏幕。
这是我的代码:Main.py:
class Navigation(FloatLayout):
pass
class Information(ScreenManager):
pass
class SlothFacts(Screen):
pass
class KiwiFacts(Screen):
pass
class MainPanel(GridLayout):
pass
Builder.load_file("mainPanel.kv")
class Complex(App):
def build(self):
return MainPanel()
if __name__ == "__main__":
Complex().run()
主面板.kv:
#:include navigation.kv
#:include images.kv
#:include config.kv
#:include information.kv
<MainPanel>:
cols:2
Navigation:
Images:
Config:
Information:
导航.kv:
<Navigation>:
Button:
text:"Kiwi"
size_hint:(.3, .2)
pos_hint:{'x':.1, 'y':.25}
#on_press: <--- Change screen to kiwi in Information class
资料.kv:
#: import FadeTransition kivy.uix.screenmanager.FadeTransition
<Information>
transition: FadeTransition()
SlothFacts:
KiwiFacts:
<SlothFacts>:
name: "sloth"
Label:
text:"im sloth"
<KiwiFacts>:
name: "kiwi"
Label:
text:"im kiwi"
慕妹3146593
相关分类