I'm using Tcl/Tk to build a GUI, for Linux environment and I saw that it's possible to "catch" a press on the 'x' button of the window (The button on the top right corner that closes the program).
How can I catch those events?
I'm using Tcl/Tk to build a GUI, for Linux environment and I saw that it's possible to "catch" a press on the 'x' button of the window (The button on the top right corner that closes the program).
How can I catch those events?
To take control of requests to delete a window, configure a suitable protocol handler:
wm protocol . WM_DELETE_WINDOW {
if {[tk_messageBox -message "Quit?" -type yesno] eq "yes"} {
exit
}
}
The default behavior (i.e., if the protocol handler is the empty string) is to just destroy
the toplevel to which the request was made.
Bind to the WM_DELETE_WINDOW
"protocol message" using the wm protocol
command.
Also note that if you just want track window destruction (on a higher level), just bind to its <Destroy>
event.