简体   繁体   中英

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):
    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:

  1. If self is an App, then self.ExitMainLoop() will close the program.
  2. If self is a Frame, then self.Close(True) is appropriate.
  3. If self is anything else, then sys.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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM