关于弹出窗口和屏幕的奇异果

时间:2019-11-01 18:39:21

标签: kivy screen popupwindow

我有一个问题,在Kivy中是否可以从弹出窗口切换到另一个屏幕?

1 个答案:

答案 0 :(得分:0)

这是一种解决方案

enter image description here

from kivy.lang.builder import Builder
from kivy.app import App
from kivy.uix.popup import Popup

kv = """
#:import Factory kivy.factory.Factory

<ChangePopup>:
    size_hint: (None, None)
    size: (200, 200)

    Button: 
        text: "Change screen"
        on_press: app.root.current = 'screen2'; root.dismiss()

ScreenManager:
    Screen:
        BoxLayout:
            orientation: 'vertical'
            Label:
                text: "Screen1"
            Button:
                text: "Open Popup to change to Screen2"
                on_press: Factory.ChangePopup().open()
    Screen:
        name: 'screen2'
        Label:
            text: "Screen2"
"""

class ChangePopup(Popup):
    pass

sm = Builder.load_string(kv)

class NewApp(App):

    def build(self):
        return sm

if __name__ == '__main__':
    NewApp().run()