Python Spyder initializing Hello World Kivi app once?

前端 未结 3 1434
攒了一身酷
攒了一身酷 2020-12-19 05:48

Does anyone know why Python\'s 2.7 Spyder is successfully initializing the \'Hello World\' Kivy app just once, i.e. hitting F5 brings the window app, but when I close it and

3条回答
  •  梦毁少年i
    2020-12-19 06:21

    Refer to the webpage: https://groups.google.com/forum/m/#!topic/kivy-users/yfhH7skAEJA, it gave a solution for fixing this issue, I rewrite the code as below,

    from kivy.app import App
    from kivy.uix.button import Button
    
    class TestApp(App):
       def build(self):
          return Button(text='Hello World')
    
    def reset():
    import kivy.core.window as window
    from kivy.base import EventLoop
    if not EventLoop.event_listeners:
        from kivy.cache import Cache
        window.Window = window.core_select_lib('window', window.window_impl, True)
        Cache.print_usage()
        for cat in Cache._categories:
            Cache._objects[cat] = {}
    
    if __name__ == '__main__':
       reset()
       TestApp().run()
    

    The reset() function will clean up the Window's state and run the TestApp() normally.

提交回复
热议问题