有谁知道为什么 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 应用程序一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何制作一个在 Python 中提供角色的不和谐机器人How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
Discord 机器人没有响应命令Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
你能得到“关于我"吗?Discord 机器人的功能?Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
message.channel.id Discord PYmessage.channel.id Discord PY(message.channel.id Discord PY)
如何在 heroku 上托管我的 discord.py 机器人?How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
discord.py - 自动更改角色颜色discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)