in reply to Re: TK::ProgressBar Color update
in thread TK::ProgressBar Color update

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

Replies are listed 'Best First'.
Re^3: TK::ProgressBar Color update
by zentara (Cardinal) on Oct 09, 2010 at 11:24 UTC
    Thanks for this excellent lesson! I was trying to go the route of eventGenerate('configure'), to trigger the update, but was running into errors.
    Tk::ProgressBar::_layoutRequest($pb, 1);

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re^3: TK::ProgressBar Color update
by Ohad (Novice) on Oct 11, 2010 at 08:10 UTC

    Thanks!!

    For your time and effort, the layoutRequest works!!