我在我的 kivy 应用程序中使用弹出窗口作为暂停菜单。但是我不知道如何用它来改变屏幕。我试过 root.manager.current 但这不起作用,因为我的弹出窗口小部件不是屏幕。我还尝试使用 self.manager.current 在 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()
千伏
<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()
App
例如,如果你在课堂上有你的屏幕管理器,你可以这样做:
app.sm.current = "menu"
然后在你的 App 类中,这样做:
self.sm = MahScreenManager()
return self.sm
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句