Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help needed.

0 views
Skip to first unread message

babas666

unread,
Sep 10, 2002, 9:42:49 AM9/10/02
to
Hi all,

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 ;
-------------------------

Glenn Jackman

unread,
Sep 10, 2002, 10:19:29 AM9/10/02
to
babas666 <baba...@metacrawler.com> wrote:
> Hi all,
>
> 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.
[...]

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

Michael Schlenker

unread,
Sep 10, 2002, 10:11:09 AM9/10/02
to
babas666 wrote:
> Hi all,
>
> 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;
> }

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


0 new messages