The application is supposed to close when I click the close button for the main frame. But the way I implemented it, it quits with a Segmentation fault when I c
One of the previous answers discusses using Destroy() rather than Close() in order to save user information before quitting the application. Here is some sample code asking the user if they intend to quit. If they respond with an affirmative, it "destroys" the frame and quits the application.
# Bind our events from our menu item and from the close dialog 'x' on the frame
def SetupEvents(self):
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
self.Bind(wx.EVT_MENU, self.OnCloseFrame, self.fileMenuExitItem)
# Destroys the main frame which quits the wxPython application
def OnExitApp(self, event):
self.Destroy()
# Makes sure the user was intending to quit the application
def OnCloseFrame(self, event):
dialog = wx.MessageDialog(self, message = "Are you sure you want to quit?", caption = "Caption", style = wx.YES_NO, pos = wx.DefaultPosition)
response = dialog.ShowModal()
if (response == wx.ID_YES):
self.OnExitApp(event)
else:
event.StopPropagation()