我是 Kivy 的新手,遇到了问题。我有“MainPanel”类,它包含四个类“导航”、“图像”、“配置”和“信息”。我想要的是当在“导航”类中按下按钮时,然后在“信息”类中使用屏幕管理器更改当前屏幕。这是我的代码:Main.py:class Navigation(FloatLayout): passclass Information(ScreenManager): passclass SlothFacts(Screen): passclass KiwiFacts(Screen): passclass MainPanel(GridLayout): passBuilder.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"
1 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
在文件中添加一个id,例如:ScreenManagermainPanel.kv
#:include navigation.kv
#:include images.kv
#:include config.kv
#:include information.kv
<MainPanel>:
cols:2
Navigation:
Images:
Config:
Information:
id: screenManager
然后,在您的Navigation.kv文件中使用它:
<Navigation>:
Button:
text:"Kiwi"
size_hint:(.3, .2)
pos_hint:{'x':.1, 'y':.25}
#on_press: <--- Change screen to kiwi in Information class
on_press: app.root.ids.screenManager.current='kiwi'
添加回答
举报
0/150
提交
取消