Python Spyder initializing Hello World Kivi app once?(Python Spyder 初始化 Hello World Kivi 应用程序一次?)
问题描述
有谁知道为什么 Python 的 2.7 Spyder 只成功初始化 'Hello World' Kivy 应用程序一次,即按 F5 会带来窗口应用程序,但是当我关闭它并再次按 F5 时,它会显示以下错误:
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
但是,通过 Anacondas 命令提示符初始化时没有错误.
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()
推荐答案
其实这个示例程序只是一个最小的结构,让你尝试如何以如此简单的方式创建交互式 UI.
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.
而在TestApp
中,它实际上并没有实现event listeners
来处理close事件.当您创建实际项目时,您应该始终注意这一点.实际上,如果您仔细查看 logging
,您会注意到错误已经在您关闭 TestApp
时发生,而不是在您重新启动"您 TestApp
:
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
因此,对于您的情况,一个简单的解决方法是在 Console
面板中转到 Run->Configure
,而不是选择 Execute in current Python or IPython console
,你只需选择第二个选项,即Execute in a new dedicated Python console
.在这种情况下,当您完成代码时,Python 将关闭当前内核.并且每当你运行你的代码时,Spyder
会自动为这个特定的脚本创建一个新的专用内核.
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.
这篇关于Python Spyder 初始化 Hello World Kivi 应用程序一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python Spyder 初始化 Hello World Kivi 应用程序一次?
基础教程推荐
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01