in reply to How to force Perl/Tk to update the GUI?
#!/usr/bin/perl use warnings; use strict; use Tk; my $toggle; my $mw = new MainWindow; my $button = $mw->Button(-text => "RUN ", -bg => 'white', -command => \&toggle)->pack(-expand=>1, -fill=>'both'); my $timer = $mw->repeat(1000,\&toggle); #notice the difference #my $timer= $mw->after(1000,\&toggle); MainLoop; sub toggle{ print $button->cget('-text'),"\n"; if ( $button->cget('-text') eq 'RUN '){ $button->configure(-text => 'STOP', -bg => 'yellow', -activebackground => 'yellow', -highlightbackground => 'yellow' ); $toggle = 1; } elsif ( $button->cget('-text') eq 'STOP'){ $button->configure(-text => 'RUN ', -bg => 'white', -activebackground => 'white', -highlightbackground => 'white' ); $toggle = 0; } }
|
|---|