Pass the command while closing Hw.Tk GUI
Hypermesh User
Altair Community Member
Hi,
I want to pass the command while closing the GUI that will unregister the proc and Unset the variables.
FYI: I no need to add a separate close button, I want to add it in that window closing button.
0
Best Answer
-
Hi,
That close button is not belonged to Tk but Windows
So, must use window manager (wm)...
Example:
proc onClosing {window} { puts -nonewline "Closing window... " set ans [tk_messageBox -title "Confirm" -message "Are you sure closing me?" -type yesno] if {$ans == "yes"} { #unset your variables here... #unregister your procs here... #finally, must explicit destroy the window: destroy $window puts "Done!" } else { puts "but not!" } } set w .sampleWindow destroy $w toplevel $w wm title $w "Sample closing window" pack [label $w.l -text "Close me by clicking on [X] upper left"] wm protocol $w WM_DELETE_WINDOW [list onClosing $w]
2
Answers
-
Hi,
That close button is not belonged to Tk but Windows
So, must use window manager (wm)...
Example:
proc onClosing {window} { puts -nonewline "Closing window... " set ans [tk_messageBox -title "Confirm" -message "Are you sure closing me?" -type yesno] if {$ans == "yes"} { #unset your variables here... #unregister your procs here... #finally, must explicit destroy the window: destroy $window puts "Done!" } else { puts "but not!" } } set w .sampleWindow destroy $w toplevel $w wm title $w "Sample closing window" pack [label $w.l -text "Close me by clicking on [X] upper left"] wm protocol $w WM_DELETE_WINDOW [list onClosing $w]
2 -
tinh said:
Hi,
That close button is not belonged to Tk but Windows
So, must use window manager (wm)...
Example:
proc onClosing {window} { puts -nonewline "Closing window... " set ans [tk_messageBox -title "Confirm" -message "Are you sure closing me?" -type yesno] if {$ans == "yes"} { #unset your variables here... #unregister your procs here... #finally, must explicit destroy the window: destroy $window puts "Done!" } else { puts "but not!" } } set w .sampleWindow destroy $w toplevel $w wm title $w "Sample closing window" pack [label $w.l -text "Close me by clicking on [X] upper left"] wm protocol $w WM_DELETE_WINDOW [list onClosing $w]
Thanks tinh,
understood the command wm protocol....
Thanks for best example..
0