Running multiple Kivy apps at same time that communicate with each other

前端 未结 3 1202
梦谈多话
梦谈多话 2020-12-15 12:45

I would like my Kivy application to be able to spawn multiple apps (i.e. new windows) on a Windows machine that can communicate with each other.

ScreenManager and Po

3条回答
  •  长情又很酷
    2020-12-15 13:22

    bj0's answer regarding subprocess was correct.

    Even better, I figured out how to do this via multiprocessing, which allows better communication and passing of information between apps. It wasn't working before because I did multiprocessing.Process(target=ChildApp().run()).start() when it should be multiprocessing.Process(target=ChildApp().run).start(). The following works

    # filename: test.py
    
    from kivy.app import App
    from kivy.uix.button import Button
    
    from test2 import ChildApp
    
    import multiprocessing
    
    
    class MainApp(App):
    
        def build(self):
            b = Button(text='Launch Child App')
            b.bind(on_press=self.launchChild)
            return b
    
        def launchChild(self, button):
            app = ChildApp()
            p = multiprocessing.Process(target=app.run)
            p.start()
    
    if __name__ == '__main__':
        MainApp().run()
    

    # filename: test2.py
    
    from kivy.app import App
    from kivy.uix.label import Label
    
    
    class ChildApp(App):
        def build(self):
            return Label(text='Child')
    
    if __name__ == '__main__':
        ChildApp().run()
    

提交回复
热议问题