Does anyone know how to trigger the progressbar's deep update without a window resize?

Short answer: yes :-)

Longer answer:

I now think I see what Ohad's problem is. I originally thought the progress bar wasn't changing as the variable was being updated.

With reference to your earlier "... you might want to build your own on a Tk::Canvas.", Tk::ProgressBar is already a derived widget based on Tk::Canvas.

The -colors option is configured as PASSIVE. It's not intended to be changed after creation of the widget. However, it can be done by accessing the private method _layoutRequest().

WARNING! Accessing private methods is bad!
The code maintainer may change it, or even remove it, at any time.
Use the following code entirely at your own risk!

OK, that's my arse covered :-) Here's the solution:

#!perl use strict; use warnings; use Tk; use Tk::Button; use Tk::ProgressBar; my $mw = MainWindow->new(); my $progress; my $toggle = 0; my @colours = ( [ 0 => q{#ff0000}, 30 => q{#00ff00}, 60 => q{#0000ff} ], [ 0 => q{#ffff00}, 30 => q{#00ffff}, 60 => q{#ff00ff} ], ); my $pb = $mw->ProgressBar( -width => 20, -length => 200, -colors => $colours[$toggle], -variable => \$progress, )->pack(); $mw->Button(-text => q{Jump WITH Change}, -command => sub { $progress ||= 0; $progress = ($progress + 10) % 110; $toggle ^= 1; $pb->configure(-colors => $colours[$toggle]); Tk::ProgressBar::_layoutRequest($pb, 1); } )->pack(); $mw->Button(-text => q{Jump NO Change}, -command => sub { $progress ||= 0; $progress = ($progress + 10) % 110; $toggle ^= 1; $pb->configure(-colors => $colours[$toggle]); } )->pack(); $mw->Button(-text => q{Exit}, -command => sub { exit })->pack(); MainLoop;

Tested successfully under Windows and Cygwin.

-- Ken


In reply to Re^2: TK::ProgressBar Color update by kcott
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.