[wxPython] wxPython newbie - wxApp.OnExit() not being called?

Can anyone tell me what I’m doing wrong

from wxPython.wx import *

class MyFrame(wxFrame):

def __init__(self, parent, id, title):
    wxFrame.__init__(self, parent, id, title, wxPoint(100, 100), wxSize(400, 400))

class MyApp(wxApp):

def OnInit(self):
    self.frame = MyFrame(NULL, -1, "This is a test")
    self.frame.Show(true)
    self.SetTopWindow(self.frame)
    return true

def OnExit(self):
    print "exit"

app = MyApp(0)
app.MainLoop()

From:
Charles Medcoff

To: wxpython-users@wxwindows.org

Sent: Saturday, August 12, 2000 1:55 PM

Subject: [wxPython] wxPython newbie - wxApp.OnExit() not being called?

Can anyone tell me what I’m doing wrong

from wxPython.wx import *

class MyFrame(wxFrame):

  def __init__(self, parent, id, title):
      wxFrame.__init__(self, parent, id, title, wxPoint(100, 100), wxSize(400, 400))

class MyApp(wxApp):

  def OnInit(self):
      self.frame = MyFrame(NULL, -1, "This is a test")
      self.frame.Show(true)
      self.SetTopWindow(self.frame)
      return true
  def OnExit(self):
      print "exit"

app = MyApp(0)
app.MainLoop()

Hi,

You didn’t call fuction OnExit to run. You should make event function and call OnExit function.Other thing def ONExit should in your myFrame class not in MyApp class

Ex:

class MyFrame(wxFrame):
def init(self, parent, id, title):
self.a=1
wxMDIParentFrame.init(self,parent,id,title,wxPyDefaultPosition, wxSize(800,600),
wxDEFAULT_FRAME_STYLE)

     # Write other code here....
     #Here you should call OnExit
     EVT_CLOSE(self, self.OnExit)

def OnExit(self,event):

     print "exit"
     self.Destroy()

class MyApp(wxApp):

  def OnInit(self):
      self.frame = MyFrame(NULL, -1, "This is a test")
      self.frame.Show(true)
      self.SetTopWindow(self.frame)
      return true

app = MyApp(0)
app.MainLoop()

···

----- Original Message -----