wxPython App - Ensure All Dialogs are Destroyed
I'm working on an application that will need to use a variety of Dialogs. I'm having trouble getting events bound in a way that ensures that my Dialogs are destroyed properly if someone closes the application before dismissing the dialogs. I would expect to use something like this:
class Form(wx.Dialog): def __init__(self): wx.Dialog.__init__(None, -1, "Dialog") self.Bind(wx.EVT_CLOSE, self.onClose) self.Bind(wx.EVT_CLOSE, self.onClose, MAIN_WINDOW) ... def onClose(self, evt): self.Destroy()
The behavior I'm currently encountering is that if someone opens a Dialog, then closes the Application before dismissing the Dialog the Application does not exit fully. MAIN_WINDOW is a reference to the Frame that's registered as my Top Level Window. Thanks in advance!
I was attempting to use event bubbling incorrectly. The solution is to make sure the Dialogs are children of the Top Level Window so that the Application exiting forces the Dialogs to destroy as well.
class Form(wx.Dialog): def __init__(self): wx.Dialog.__init__(MAIN_WINDOW, -1, "Dialog") self.Bind(wx.EVT_CLOSE, self.onClose) ... def onClose(self, evt): self.Destroy()