user825286
user825286

Reputation:

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)

Upvotes: 0

Views: 2853

Answers (4)

Gregory Kakhiani
Gregory Kakhiani

Reputation: 1

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)

Upvotes: 0

Johan Kotlinski
Johan Kotlinski

Reputation: 25759

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

Upvotes: 5

Manny D
Manny D

Reputation: 20744

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.

Upvotes: 1

g.d.d.c
g.d.d.c

Reputation: 48028

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.

Upvotes: 2

Related Questions