Re: Bug in STk-3.99.4 related to <Destroy> event

From: Erick Gallesio <>
Date: Sat, 27 Feb 1999 09:06:49 +0100 (CET)

David Fox writes:
> If you add the following binding to the end of Demos/browse.stk you
> get a "Goodbye" message when you hit the "Quit" button:
> (bind .f.list "<Destroy>"
> (lambda () (format (current-error-port) "Goodbye~%")))
> However, if you add a window parameter you will get an error:
> (bind .f.list "<Destroy>"
> (lambda (|W|) (format (current-error-port) "Goodbye~%")))
> *** Background error:
> unbound variable: .f.list
> #### WARNING: error occurred while executing the body of report-error!!
> [...]
> Please help!

This is not a bug but rather a Tk feature. In fact, the object is
destroyed and AFTER that the binding is execute. The Tcl/Tk example
below exemplifies this:
   button .b -text
   pack .b
   bind .b <Destroy> {%W configure -bg red}
   destroy .b
will lead to an ``invalid command name ".b"'' message

The only way I know to capture such an event is to use the
"WM_DELETE_WINDOW" protocol of the toplevel which contains
the widget. Something like:

        (button '.b :text "foo")
        (pack .b)
        (wm 'protocol *root* "WM_DELETE_WINDOW"
            (lambda ()
                (display "Hello\n")
                ; eventually destroy the window. Since this will not
                ; be done now that we have set the delete window
                ; protocol

Hope it helps

                -- Erick
Received on Sat Feb 27 1999 - 09:33:33 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST