任何人都可以幫我弄清楚我在做什麼錯我對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