OnExit closes windows, but dosen't exit application - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: OnExit closes windows, but dosen't exit application (/thread-5218.html) |
OnExit closes windows, but dosen't exit application - Larz60+ - Sep-22-2017 In the following code when I click the 'X' on main window, the windows are destroys, but the application keeps running. Thought I knew how to do this, but guess not. import wx import wx import sys class NewPanel(wx.Panel): def __init__(self, parent): super(NewPanel, self).__init__(parent) class NewFrame(wx.Frame): def __init__(self, parent, title=""): super(NewFrame, self).__init__(parent, title=title) self.panel = NewPanel(self) class DocViewer(wx.App): def __init__(self, win_title=''): super(DocViewer, self).__init__(win_title) self.urls = { 'rfc_zips': 'https://www.rfc-editor.org/in-notes/tar/RFC-all.zip', 'standards_page': 'https://www.rfc-editor.org/standards' } self.frame = NewFrame(None, title=win_title) self.frame.Show() self.frame.Bind(wx.EVT_MENU, self.OnExitApp) def OnExitApp(self, event): self.frame.Destroy() sys.exit(0) if __name__ == "__main__": app = wx.App(redirect=False) DocViewer(win_title="RFC Viewer (c) Larz60+ 2017") app.MainLoop() RE: OnExit closes windows, but dosen't exit application - metulburr - Sep-23-2017 i get this error on linux after the windows closes, then a segmentation fault. https://github.com/wxWidgets/wxWidgets/blob/master/src/unix/threadpsx.cpp#L340 This seems to fix it for me self.frame.Bind(wx.EVT_CLOSE, self.OnExitApp)instead of self.frame.Bind(wx.EVT_MENU, self.OnExitApp) RE: OnExit closes windows, but dosen't exit application - Larz60+ - Sep-23-2017 That works! Thanks a bunch! RE: OnExit closes windows, but dosen't exit application - snippsat - Sep-23-2017 Full super() power,leave python 2 support behind import wx import sys class NewPanel(wx.Panel): def __init__(self, parent): super().__init__(parent) class NewFrame(wx.Frame): def __init__(self, parent, title=""): super().__init__(parent, title=title) self.panel = NewPanel(self) class DocViewer(wx.App): def __init__(self, win_title=''): super().__init__(win_title) self.urls = { 'rfc_zips': 'https://www.rfc-editor.org/in-notes/tar/RFC-all.zip', 'standards_page': 'https://www.rfc-editor.org/standards' } self.frame = NewFrame(None, title=win_title) self.frame.Show() self.frame.Bind(wx.EVT_CLOSE, self.OnExitApp) def OnExitApp(self, event): self.frame.Destroy() sys.exit(0) if __name__ == "__main__": app = wx.App(redirect=False) DocViewer(win_title="RFC Viewer (c) Larz60+ 2017") app.MainLoop() |