in reply to Changing the button function
If you think about it, you can have more than 2 options by extending the idea.
#!/usr/bin/perl use warnings; use strict; use Tk; my $toggle = 0; my $mw = MainWindow->new(-title => "Testing ToggleButton\n"); my $button = $mw->Button(-text => "RUN", -bg => 'white', -command => \&toggle)->pack(-expand=>1, -fill=>'b +oth'); MainLoop; sub toggle{ print $button->cget('-text'),"\n"; if ( $button->cget('-text') eq 'RUN'){ $button->configure(-text => 'STOP', -bg => 'yellow', -activebackground => 'yellow', -highlightbackground => 'yellow', ); print "Do your RUN stuff here\n"; $toggle = 1; } elsif ( $button->cget('-text') eq 'STOP'){ $button->configure(-text => 'RUN', -bg => 'white', -activebackground => 'white', -highlightbackground => 'white', ); print "Do your STOP stuff here\n"; $toggle = 0; } }
|
|---|