Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

catch clicks on the 'x' button using Tk Tcl

Tags:

exit

tk

tcl

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?

like image 990
SIMEL Avatar asked Nov 02 '11 12:11

SIMEL


1 Answers

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.

like image 159
Donal Fellows Avatar answered Sep 30 '22 07:09

Donal Fellows