#!/usr/bin/perl use strict; use Tk; use Tk::ProgressBar; our $percent_done = 0; our $stopped = 0; my $mw = new MainWindow; $mw->geometry('200x100+100+100'); my $progress = $mw->ProgressBar( -width => 40, -height => 20, -from => 0, -to => 100, -blocks => 50, -colors => [0, 'blue',30,'yellow',70,'orange'], -variable => \$percent_done )->pack(-expand=>1, -fill=>'x'); my $buttonF = $mw->Frame->pack; my $timer; my $startB = $buttonF->Button( -text => 'start', -command => sub { $stopped = 0; $percent_done = 0; #restore original colors $progress->configure('-colors',[0, 'blue',30,'yellow',70,'orange'] ); $mw->idletasks; # these commands $mw->update; # don't seem to work #but a window resize does $timer = $mw->repeat(50, sub{ $percent_done++; $progress->update; if ($stopped) { #set red colors $progress->configure('-colors', [0, 'red',30,'red',70,'red'] ); $mw->idletasks; # these commands $mw->update; # don't seem to work #but a window resize does $timer->cancel; } }) } )->pack(-side => 'left'); my $stopB = $buttonF->Button( -text => "stop", -command => sub { $stopped = 1; } )->pack(-side => 'left'); MainLoop;