http://qs1969.pair.com?node_id=63772

kb2yht has asked for the wisdom of the Perl Monks concerning the following question:

Hi perl Monks.

I'me trying to make a, err... well ... its a Tk window with a Label in it,
thats it, and the label just has a number in it.
The Number is stored in $foo. and is updated by the program every 5sec or so.
How do I get the number to update in the Tk window ??
the window is just
$mw = MainWindow->new;
$tes = $mw->Label(-text=> "$foo");
$tes->pack;
MainLoop;

I know it must be trivial to do ,
I just cant do it :-( .
Many thnaks
Bill.

Replies are listed 'Best First'.
Re: Real simple Tk label
by danger (Priest) on Mar 12, 2001 at 12:25 UTC

    I think you are looking for the -textvariable option, and give it a reference to a scalar:

    #!/usr/bin/perl -w use strict; use Tk; my $foo = 500; my $mw = MainWindow->new; my $tes = $mw->Label(-textvariable => \$foo); $tes->pack; $mw->repeat(3000,sub{$foo++}); MainLoop(); __END__