Detect TKinter window being closed?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Glen

    Detect TKinter window being closed?

    Is it possible to to detect a Tkinter top-level window being closed with the
    close icon/button (top right), for example to call a function before the
    window actually closes?

    Python 2.4 / Linux (2.6 kernel) if that makes any difference.
    Any info would be greatly appreciated.
    Thanks
    Glen
  • Adonis

    #2
    Re: Detect TKinter window being closed?

    Glen wrote:[color=blue]
    > Is it possible to to detect a Tkinter top-level window being closed with the
    > close icon/button (top right), for example to call a function before the
    > window actually closes?
    >
    > Python 2.4 / Linux (2.6 kernel) if that makes any difference.
    > Any info would be greatly appreciated.
    > Thanks
    > Glen[/color]

    Here is an example code taken from:

    (located at very end)

    Example 7-2. Capturing destroy events

    # File: protocol1.py

    from Tkinter import *
    import tkMessageBox

    def callback():
    if tkMessageBox.as kokcancel("Quit ", "Do you really wish to quit?"):
    root.destroy()

    root = Tk()
    root.protocol(" WM_DELETE_WINDO W", callback)

    root.mainloop()

    Hope this helps.

    Adonis

    Comment

    • Fredrik Lundh

      #3
      Re: Detect TKinter window being closed?

      Glen wrote:
      [color=blue]
      > Is it possible to to detect a Tkinter top-level window being closed with the
      > close icon/button (top right), for example to call a function before the
      > window actually closes?[/color]



      </F>



      Comment

      • Glen

        #4
        Re: Detect TKinter window being closed?

        Thanks Fredrik and Adonis that's just what I needed, plus a bit more to
        learn about.

        Comment

        Working...