我正在尝试使用spyder IDE(版本3.3.0)执行以下python脚本。我是新手,所以仍然想尝试一下。
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.core.window import Window
Window.size = (200, 100)
class Test_Screen(GridLayout):
def __init__(self, **kwargs):
super(Test_Screen, self).__init__(**kwargs)
self.rows = 2
test_label = Label(text='Hello, world', color=(1, 0, 0, 1))
self.add_widget(test_label)
test_button = Button(text='Button', color=(1, 0, 0, 1))
self.add_widget(test_button)
class Test_Kivy(App):
def build(self):
return Test_Screen()
kivy_object = Test_Kivy()
kivy_object.run()
程序第一次成功运行。但是,当我第二次尝试执行它时,出现错误。下面是在spyder的Console 1/A
中看到的第一轮和第二轮的完整屏幕截图。
首次执行(成功运行):
runfile('D:/SIPRA/Programs/kivy_test.py', wdir='D:/SIPRA/Programs')
[INFO ] [Logger ] Record log in C:\Users\SIPRA\.kivy\logs\kivy_18-07-22_68.txt
[INFO ] [Kivy ] v1.10.1
[INFO ] [Python ] v3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
[INFO ] [Factory ] 194 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
Purge log fired. Analysing...
Purge finished!
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.6.0 NVIDIA 398.36'>
[INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO ] [GL ] OpenGL renderer <b'GeForce GTX 1080 Ti/PCIe/SSE2'>
[INFO ] [GL ] OpenGL parsed version: 4, 6
[INFO ] [GL ] Shading version <b'4.60 NVIDIA'>
[INFO ] [GL ] Texture max size <32768>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[INFO ] [Base ] Leaving application in progress...
立即执行第二次(引发错误):
runfile('D:/SIPRA/Programs/kivy_test.py', wdir='D:/SIPRA/Programs')
[INFO ] [Base ] Start application main loop
[ERROR ] [Base ] No event listeners have been created
[ERROR ] [Base ] Application will leave
当我尝试从IDLE执行该代码时,每次都运行相同的代码而没有任何错误。我正在使用Python 3.7 64位,并且我的操作系统是Windows 10(64位)。间谍版本为3.3.0。 Kivy版本为V1.10.1。我已经看过该SO线程中出现的问题-“ Spyder not running Kivy script”,但这是针对较旧版本的spyder的,该错误似乎与我遇到的错误有所不同。因此发布了一个新问题。知道我做错了什么吗?