wxPython question: window closing event

Cliff Wells logiplexsoftware at earthlink.net
Mon Jun 24 14:01:12 EDT 2002


On Mon, 24 Jun 2002 17:45:59 GMT
Mike Christie wrote:

> I have a specific and a general question about wxPython.  I have worked with
> GUIs and event-handlers before, but am new to both wxPython and Python
itself.
> 
> The specific question is: how do I attach code to the window closing event
> that occurs when (in MS Windows systems) you click the X in the top right
> corner of the screen?  It appears I need to place a "self.close(true)" there,
> since exiting via an exit menu (which does call "self.close(true)") shuts
> things down politely, but exiting via the X leaves the Python interpreter
> still executing my script, and forces me to close Python to shut it down.

from wxPython.wx import *

class MyFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, "A Frame")
        EVT_CLOSE(self, self.OnClose)

    def OnClose(self, event):
        self.Destroy()
        print "Destroyed!"
        
app = wxPySimpleApp()
frame = MyFrame()
frame.Show(true)
app.MainLoop()


> The general question is: what's the best resource for finding this sort of
> thing out?  I've been working through the tutorial material at
> http://wiki.wxpython.org/index.cgi/Getting_20Started which has been very
> helpful indeed.  I've also made some use of the online documentation at
> http://wxpython.org/onlinedocs.php which is also great.  However, for a
> question like this, it seems like the right resource is something like a
> categorization of events, or a reference guide for event-handling, or
> something like that.   The online docs do have an "Event Handling Overview",
> but I couldn't find this information there.  Is there a book or online
> reference that I could use as a resource for this kind of question?

The best quick-reference is probably the demo that comes with wxPython (you can
download it from the wxPython website).

Also, questions like this are probably better answered on the wxPython mailing
list (which you can also subscribe to via the wxPython website).

Regards,

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308





More information about the Python-list mailing list