I am new to tcl/tk.
I wonder why when I click on the button my label doesn't update.
If I use " -command {set Result [my_prog_to_get_stat]} " instead of
"get_stat" it works.
I need your advice.
Thanks
-------------------------
proc get_stat { } {
set Result [my_prog_to_get_stat];
pack .f.cpu;
}
frame .f;
pack .f \
-fill x;
label .f.cpu \
-textvariable Result;
pack .f.cpu;
button .f.calc \
-command get_stat \
-text Get;
pack .f.calc ;
-------------------------
Because, in [label .f.cpu -textvariable Result], Result is a global
variable, and in [proc get_stat {} {set Result ...}], Result is local.
Use this modification:
proc get_stat { } {
global Result
set Result [my_prog_to_get_stat]
pack .f.cpu
}
--
Glenn Jackman
gle...@ncf.ca
Result is a local var, the Result you use in label is a global one.
Try this:
proc get_stat { } {
global Result
set Result [my_prog_to_get_stat]
}
or (if Tcl 8.x)
proc get_stat { } {
set ::Result [my_prg_to_get_stat]
}
BTW. your call to pack .f.cpu in this proc is probably wrong and does
not what you want. To force a display update use [update idletasks] or
[update], but you probably do not have to force it for this example.
Take a look at:
http://mini.net/tcl/global
Michael Schlenker