Main Content

Making a variable dynamically visible in a Tcl/Tk GUI

Archive - Originally posted on "The Horse's Mouth" - 2007-12-15 21:45:33 - Graham Ellis

set bill "and Ben"
label .about -textvariable bill
button .first -text "First" -command {set bill Bradshaw}
button .second -text "Second" -command {set bill Bailey}
button .done -text quit -command exit
pack .about .first .second .done


Tcl/Tk's -textvariable option, on commands like label and button, allows you to have the contents of a variable display within you GUI (Graphic User Interface) ... and simply changing the value in the variable will change your display.

Quick, elegant, easy to program and easy to maintain.