我是 wxPython 的新手。从一个简单的教程(http://wiki.wxpython.org/wxPython%20by%20Example)开始,似乎Spyder和wxPython之间存在冲突。我可以运行以下脚本一次(在 IPython 控制台中),使用:
runfile(r'C:\Python27\Scripts\test\test.py')
其中包含:
import wx
class Frame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, title=title, size=(350,200))
app = wx.App(redirect=True)
top = Frame("Hello World")
top.Show()
app.MainLoop()
但是我第二次运行它,我得到了以下错误:
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 493, in runfile
execfile(filename, namespace)
File "C:\Python27\Scripts\test\test.py", line 14, in <module>
top = Frame("Hello World")
File "C:\Python27\Scripts\test\test.py", line 11, in __init__
wx.Frame.__init__(self, None, title=title, size=(350,200))
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 505, in __init__
_windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
PyNoAppError: The wx.App object must be created first!
它不太明白,但显然它与 spyder 是使用 wxPython 编写的并且与 app.MainLoop() 冲突有关
有人可以确认和/或解释更多吗?
非常感谢,
帕特里克