任何人都可以帮我弄清楚我在做什么错我对GUI很少有经验。 代码:Python,wxPython错误
import wx
class bucky(wx.Frame):
#constructor
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Frame aka window',size=(300,200))
panel=wx.Panel(self)
button=wx.Button(panel,label="exit",pos=(130,10),size=(60,60))
self.Bind(wx.EVT_BUTTON, self.closebutton,button)
self.Bind(wx.EVT_CLOSE, self.closewindow)
def closebutton(self,event):
self.close(True)
def closewindow(self,event):
self.Destroy()
if __name__=='__main__':
app=wx.PySimpleApp()
frame=bucky(parent=None,id=-1)
frame.Show()
app.MainLoop()
错误:
PyNoAppError: The wx.App object must be created first!
win32ui.error: Error in Command Message handler for command ID 36864, Code 0
请尝试修复代码的缩进,以便在文本编辑器中缩放所有内容 - 它在Python中非常重要。 – Marius
我想你不想第三个参数在这里'self.Bind(wx.EVT_BUTTON,self.closebutton,button)' –
这是完整的追溯?它是否告诉你该错误来自哪条线? – Blair