我在我的kivy应用中使用弹出窗口作为暂停菜单。但我无法弄清楚如何用它来改变屏幕。我尝试过root.manager.current,但由于我的弹出窗口小部件不是屏幕,因此无效。我也尝试使用self.manager.current在python中创建一个函数但是唉也没用。这是我现在能想到的唯一想法,但它也不起作用。任何和所有的帮助表示赞赏。
python代码段
class PausePopup(Popup):
pass
class MahScreenManager(ScreenManager):
pass
class MahMenu(Screen):
pass
class MahGame(Screen):
class MahGameApp(App):
def build(self):
window_color = get_color_from_hex("#eaeaea")
Window.clearcolor = window_color
return MahScreenManager()
MahGameApp().run()
KV
<MahScreenManager>:
MahMenu:
name: "menu"
id: menu
MahGame:
name: "game"
id: game
<PausePopup>:
title: "Gahme is paused"
size_hint: .5, .7
BoxLayout:
orientation: "vertical"
padding: 10
spacing: 10
Button:
text: "Continue"
on_release: root.dismiss()
Button:
text: "Settings"
on_release: app.open_settings()
Button:
text: "Main Menu"
on_release: Factory.MahGame().current = "menu"
<MahMenu>:
BoxLayout:
padding: 50
spacing: 25
orientation: "vertical"
Button:
text: "Start Mah Gahme"
on_release:
root.manager.transition.direction = "left"
root.manager.current = "game"
Button:
text: "Quit"
on_release: app.stop()
<MahGame>:
Button:
text: "Pause"
size_hint: 0.1, 0.1
on_release: Factory.PausePopup().open()
答案 0 :(得分:1)
如果您在App
课程中有屏幕管理员,可以这样做:
app.sm.current = "menu"
然后在你的App类中,这样做:
self.sm = MahScreenManager()
return self.sm