[英]kivy - I want to change an attribute of a widget in a screen out of a popup
[英]How to change screen with a popup widget in kivy?
我在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()
例如,如果您的屏幕管理器位于App
类中,则可以这样:
app.sm.current = "menu"
然后在您的App类中,如下所示:
self.sm = MahScreenManager()
return self.sm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.