in reply to TK::ProgressBar Color update

Hi,

Here is an example that does what I think you want. It is a hack that swaps colors. The problem with it, is once all colors are swapped to red, it is tricky to restore original bar colors. I used red1, red2, red3 to differentiate and restore. It would seem that you could itemconfigure the progressbar for -colors, to restore original bar colors, but it dosn't seem to work.

I hope it stimulates a solution for you.

#!/usr/bin/perl use strict; use Tk; use Tk::ProgressBar; our $percent_done = 0; our $stopped = 0; my $mw = MainWindow->new(qw/-title Working/); my $progress = $mw->ProgressBar( -width => 20, -height => 400, -from => 0, -to => 100, -blocks => 50, -colors => [0, 'blue',30,'yellow',70,'orange'], -variable => \$percent_done )->pack; my $buttonF = $mw->Frame->pack; my $startB = $buttonF->Button( -text => 'start', -command => sub { $stopped = 0; $percent_done = 0; # hack to restore colors, I use different red shades # but you could store the information in a hash somehow # to get back to the original colors swapColor($progress, "red1", "blue"); swapColor($progress, "red2", "yellow"); swapColor($progress, "red3", "orange"); foreach my $x (1 .. 100) { select(undef,undef,undef,.05); if ($stopped) { swapColor($progress, "blue", "red1"); swapColor($progress, "yellow", "red2"); swapColor($progress, "orange", "red3"); return; } $percent_done = $x; $progress->update; } })->pack(-side => 'left'); my $stopB = $buttonF->Button( -text => "stop", -command => sub { $stopped = 1; } )->pack(-side => 'left'); MainLoop; sub swapColor { my ($pb, $oldColor, $newColor) = @_; foreach my $tag ($pb->find("all")) { print $tag,'->',$pb->itemcget($tag, "-fill"),"\n"; if ($pb->itemcget($tag, "-fill") eq $oldColor) { $pb->itemconfigure($tag, -fill => $newColor); } } print "\n\n"; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh