Python Forum
OnExit closes windows, but dosen't exit application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OnExit closes windows, but dosen't exit application
#1
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()
Reply
#2
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)
Recommended Tutorials:
Reply
#3
That works! Thanks a bunch!
Reply
#4
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can application developed Run on windows of users? Acernz 3 2,267 Oct-18-2020, 01:14 PM
Last Post: jefsummers
  [Tkinter] How to close all windows when exit program scratchmyhead 3 6,313 May-17-2020, 08:19 AM
Last Post: menator01
  [Tkinter] How to exit when multiple root windows. weatherman 4 5,459 May-10-2018, 11:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020