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

In reply to Re: TK::ProgressBar Color update by zentara
in thread TK::ProgressBar Color update by Ohad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.