YUCK! That's some horrible code you found.
The $text_label should be a Frame, not a Label. The whole 'Intialize' should be redone with ->repeat.
Here's how I would do the spirit of this program.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11163827 use warnings; use Tk; my ($red, $green, $blue) = (0, 50, 100); my %colorhash = (Red => \$red, Green => \$green, Blue => \$blue); my $mw = MainWindow->new; $mw->geometry( '300x100+500+400' ); my $row = 1; for ( qw( Red Green Blue ) ) { $mw->Label(-text => $_, )->grid(-row => $row, -column => 1, -sticky => 'w'); $mw->Label(-textvariable => $colorhash{$_}, )->grid(-row => $row++, -column => 2, -sticky => 'e'); } my $color = 0; $mw->repeat( 1000, \&change ); $mw->repeat( 1777, sub {-M $0 < 0 and exec $0}); # restart when code c +hanges MainLoop; sub change { ( sub { $red = int rand 50 }, sub { $green = 50 + int rand 50 }, sub { $blue = 100 + int rand 50 } )[ $color = ( $color + 1 ) % 3 ](); }
In reply to Re: Basic questions of Tk programming
by tybalt89
in thread Basic questions of Tk programming
by jmClifford
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |