大侠请留步!!! wxpython :怎么样绑定 主窗口 的 关闭按钮
wxpython :怎么样绑定 主窗口 的 关闭按钮? 想在退出前,进行一些操作
- Python code
def __init__(self): wx.Frame.__init__(self, None, -1, "Produce Auto Test Paltform",pos=wx.DefaultPosition, size = (900,600), style=wx.DEFAULT_FRAME_STYLE |wx.SUNKEN_BORDER |wx.CLIP_CHILDREN )
[解决办法]
self.Bind(wx.EVT_CLOSE, self.OnClose)
红字参数是个函数本身,你主动调用变成返回值None,另外OnClose最后需要调用evt.Skip()继续执行默认的关闭动作...
- Python code
import wxclass myframe(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Bitmap Button Example', size=(200, 150)) self.Bind(wx.EVT_CLOSE,self.OnClose) def OnClose(self, evt): ret = wx.MessageBox('Do you really want to leave?', 'Confirm', wx.OK|wx.CANCEL) if ret == wx.OK: # do something here... evt.Skip() if __name__ == '__main__': app = wx.PySimpleApp() frame = myframe() frame.Show() app.MainLoop()