Here is a simple example: Happy Memorial Day!
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $mw = MainWindow->new;
$mw->geometry('300x200');
my $timer; # global for timer
my @color = qw/red black/;
my $bits = pack("b16"x8,
"1111111111111111",
".11111111111111.",
"..111111111111..",
"...1111111111...",
"....11111111....",
".....11111......",
"......111.......",
".......1........",);
$mw->DefineBitmap('indicator' => 16,8, $bits);
my $label = $mw->Label(
-bitmap=>'indicator',
-bg=>'black',
-fg=>'red')->pack;
my $button = $mw->Button(-text => 'Start',
-command => \&change_label)->pack();
MainLoop;
sub change_label {
if ($button->cget('-text') eq "Start"){
$button->configure(-text => 'Stop');
$timer = $mw->repeat(100,
sub{$label->configure(-fg=>$color[0]);
@color=reverse(@color);
});
} else {
$button->configure(-text => 'Start');
$timer->cancel;
}
}
|