Python Forum

Full Version: OnExit closes windows, but dosen't exit application
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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()
i get this error on linux after the windows closes, then a segmentation fault.
https://github.com/wxWidgets/wxWidgets/b...x.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)
That works! Thanks a bunch!
Full super() power,leave python 2 support behind Wink
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()