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 hit F5 again, it says the following error:
[INFO ] [Base ] Start application main loop
[ERROR ] [Base ] No event listeners have been created
[ERROR ] [Base ] Application will leave
However, there is no error when initialized through Anacondas Command Prompt.
Here's the code (same as website):
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello World')
TestApp().run()
if __name__ == '__main__':
TestApp().run()
class MyFirstKivyApp(App): def build(self): return Label(text ="Hello World !")
Build and distribute beautiful Python cross-platform GUI apps with ease. Kivy runs on Android, iOS, Linux, macOS and Windows. Get started! Kivy has been built to be easy to use, cross-platform and fast.
Kivy helps us to design innovative user interfaces with multi-touch functionalities. It can smoothly work with various platforms such as Windows, Android, Linux, iOs, macOS, and Raspberry Pi. It helps us to run code on all supported platforms. It provides well-documented APIs.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With