wxPython window won't close
When you click on Cancel, it cancels... When you click OK, it pops the dialog back on. How can I fix this?
def quitApp(self, event):开发者_如何学JAVA
dial = wx.MessageDialog(None, 'Are you sure you want to quit?','Quit', wxYES | wxNO)
if dial.ShowModal() == wxID_YES:
self.Close(true)
Could it be that quitApp is called by the system CloseEvent handler? In that case, self.Close(true) only triggers a new CloseEvent, which in that case will call quitApp again and show a new dialog... and so on.
I suggest you quit the application with sys.exit(0) instead of self.Close(true).
Without knowing more (see my comment), I can take a few stabs:
- If
self
is an App, thenself.ExitMainLoop()
will close the program. - If
self
is a Frame, thenself.Close(True)
is appropriate. - If
self
is anything else, thensys.exit(0)
will shut down the Python Interpreter and close the program.
You'll need to provide more code. It looks like something else is triggering the quitApp
function. Your function right there doesn't loop. It might be looping because it's trying to close and the event keeps getting called. Try using self.Destroy()
instead to close the frame.
def CloseTheProgram( self, event ):
dial = wx.MessageDialog(None, 'Are you sure you want to quit?','Quit', wx.YES | wx.NO)
if dial.ShowModal() == wx.ID_YES:
self.Close(True)
精彩评论