#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Location
    INDIA
    Posts
    31
    Rep Power
    11

    How to track that close button on title bar is clicked?


    Hello

    I just want to know that how this can be tracked that close button title bar is clicked?

    Top - Right hand of any window of application.

    I just want to track that this cross button is closed.

    In my application some connections are running and if somebody just clicks the close button on top right of the title bar then I must close the connection and then exit from the application?


    How to do this??

    Thanks in advance

    Sandeep
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Use that atexit module. This will let you run a function when the X button is pressed or any other method of closing your program occurs.
    Code:
    import atexit
    def onexit():
        print 'Exiting application...'
    atexit.register(onexit)
    You use the register function of the atexit module to register a function to run at program exit. You can register as many functions as you want.
  4. #3
  5. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    If it is a Tkinter or wxPython application then you can handle the event directly:

    wxPython:
    Code:
        def __init__(self.....):
           .....
            EVT_CLOSE(self, self.OnWxFrame1Close)
          ......
    
        def OnWxFrame1Close(self, event):
            #your code
            .....
            self.Close() OR USE self.Destroy() # see docs
    For Tkinter have a look at this section on events:
    Tkinter Events

    grim

IMN logo majestic logo threadwatch logo seochat tools logo