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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |