看看这段Python代码问题出在哪
悲酥清风 2009-09-10 05:10:01 照着书上写的,执行时报错(Python2.6)
import wx
class InsertFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame With Button',size=(300,100))
panel = wx.Panel(self)
button = wx.Button(panel,label="Close",pos=(125,20),
size=(50,50))
self.Bind(wx.EVT_BUTTON,self.OnCloseMe,button)
self.Bind(wx.EVT_CLOSE,self.OnCloseWindow)
def OnCloseMe(self,event):
self.Close(True)
def OnCloseWindow(self,event):
self.Destroy()
if __name__=='__main__':
app = wx.PySimpleApp()
frame = InsertFrame(parent=None,id=-1)
frame.Show()
app.MainLoop()
报错信息如下:
Traceback (most recent call last):
File "D:\Python26\test\wx\button.py", line 19, in <module>
frame = InsertFrame(parent=None,id=-1)
File "D:\Python26\test\wx\button.py", line 4, in __init__
wx.Frame.__init__(self,parent,id,'Frame With Button',size=(300,100))
File "D:\Python26\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!
刚开始学,还不太懂