我有一个框架,一旦用户点击退出按钮,我想要一个对话框打开并询问他是否真的想关闭窗口。如何在wxPython中引发wx.EVT_CLOSE之后停止关闭窗口?
所以我做:
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
,然后我有回调:
def OnCloseWindow(self, event):
dialog = wx.MessageDialog(self, message = "Are you sure you want to quit?", caption = "Caption", style = wx.YES_NO, pos = wx.DefaultPosition)
response = dialog.ShowModal()
if (response == wx.ID_YES):
Pairs = []
self.list_ctrl_1.DeleteAllItems()
self.index = 0
self.Destroy()
elif (response == wx.ID_NO):
wx.CloseEvent.Veto(True)
event.Skip()
这工作,但我得到的错误:
TypeError: unbound method Veto() must be called with CloseEvent instance as first argument (got bool instance instead)
如何赶上引发事件的closeWindows实例?
嗯,在我的代码中,似乎我甚至不需要它。如果我捕获该事件并且不显式调用'self.Destroy()',则该窗口不会关闭。我也不会调用'event.Skip()'。我或者自己关闭窗户。就是这样。 – Fenikso 2014-10-10 15:06:08
你可以发布你的代码吗?不太明白你做了什么! – 2014-10-10 16:46:36