If you run this script, and hit Stop, the bar will turn red only after you just SLIGHTLY resize the window. The same occurs after a second START, the bar returns to original colors after a slight resize of the window.
I tried update, packPropagate, idletasks, etc. to stimulate the update, but no luck.
Does anyone know how to trigger the progressbar's deep update without a window resize? I suppose as a hack, the Start and Stop buttons could include some code to do a 1-pixel resize of the $mw. :-)
#!/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;
In reply to Re: TK::ProgressBar Color update
by zentara
in thread TK::ProgressBar Color update
by Ohad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |