Kivy是使用Python进行APP开发的工具,国内相关资料较少。
装好kivy之后,我发现写好的程序第一次调试运行正常。
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello World!')
if __name__ == '__main__':
MyApp().run()
但是第二次运行这个程序时就会报错:
[INFO ] [Base ] Start application main loop
[ERROR ] [Base ] No event listeners have been created
[ERROR ] [Base ] Application will leave
[INFO ] [Base ] Leaving application in progress
ArgumentError: argument 3: <class 'TypeError'>: wrong type
后来到Stackoverflow上面才找到了解决方案,只要再写一个重置的函数,在每次运行前执行一下就好啦。
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(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()
MyApp().run()
希望能帮助到有需要的朋友。