【发布时间】:2012-12-17 03:37:34
【问题描述】:
谁能帮我找出我做错了什么我对 GUI 的经验很少。 代码:
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 中非常重要。
-
我想你不想要这里的第三个参数
self.Bind(wx.EVT_BUTTON, self.closebutton,button) -
这是完整的回溯吗?它是否告诉您该错误来自哪一行?
-
@JoranBeasley - 实际上这是正确的。请参阅wiki.wxpython.org/self.Bind%20vs.%20self.button.Bind 了解更多信息
-
哦,对了,我以为他是直接绑定到按钮上的:P