开发者

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:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜