Python Spyder initializing Hello World Kivi app once?

蓝咒 提交于 2019-11-29 10:40:04

Actually the sample program is just a minimum structure for you to try out how the interactive UI can be created in such a simple way.

And the in TestApp, it actually didn't implment the event listerners to handle the close event. And when you create your actual project, you should always take care of that. Acually if you look at the logging carefully, you would notice that the error happens already when you close the TestApp, not when you "re-start" you TestApp:

[INFO              ] [Base        ] Leaving application in progress...
INFO:kivy:[Base        ] Leaving application in progress...
[INFO              ] [Base        ] Start application main loop
INFO:kivy:[Base        ] Start application main loop
[ERROR             ] [Base        ] No event listeners have been created
ERROR:kivy:[Base        ] No event listeners have been created
[ERROR             ] [Base        ] Application will leave
ERROR:kivy:[Base        ] Application will leave

So for your case, the one simple work-around is that you go to Run->Configure, in the Console panel, instead of you choose to Execute in current Python or IPython console, you just choose the second option, which is Execute in a new dedicated Python console. In this case, where time your finished the code, the Python will close the current kernel. And whenever you run your code, Spyder will automatically create a new dedicated kernel for this particular script.

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.

For use in external system terminal will solve this. Part 1

Part 2

Part 3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!