Pass the command while closing Hw.Tk GUI

Hypermesh User
Hypermesh User Altair Community Member
edited January 2021 in Community Q&A

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. 

 

image

Best Answer

  • tinh
    tinh Altair Community Member
    edited January 2021 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]

Answers

  • tinh
    tinh Altair Community Member
    edited January 2021 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]
  • Hypermesh User
    Hypermesh User Altair Community Member
    edited January 2021
    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..