edpatterson
IS-IT--Management
- Feb 24, 2005
- 186
Please let me know if this belongs in the Perl area.
I can not get the button background color to change based upon button selection. The button should be gree for start and red for stop. It stays green no matters what the textvailable is.
[tt]
#!/usr/bin/perl -w
use strict;
use Tk;
my $mode = 'Start';
my $color = 'green';
my $mw = MainWindow->new;
my $lbl = $mw->Label(-text=>'Button Basics')->pack;
my $btn = $mw->Button(-textvariable=>\$mode,
-background =>$color,
-command=> sub {
if($mode eq 'Start'){
$color = 'red';
$mode = 'Stop';
}else{
$color = 'green';
$mode = 'Start';
}
}
)->pack(-side=>'bottom');
MainLoop;
[/tt]
Thanks,
Ed
I can not get the button background color to change based upon button selection. The button should be gree for start and red for stop. It stays green no matters what the textvailable is.
[tt]
#!/usr/bin/perl -w
use strict;
use Tk;
my $mode = 'Start';
my $color = 'green';
my $mw = MainWindow->new;
my $lbl = $mw->Label(-text=>'Button Basics')->pack;
my $btn = $mw->Button(-textvariable=>\$mode,
-background =>$color,
-command=> sub {
if($mode eq 'Start'){
$color = 'red';
$mode = 'Stop';
}else{
$color = 'green';
$mode = 'Start';
}
}
)->pack(-side=>'bottom');
MainLoop;
[/tt]
Thanks,
Ed