If you want a way to update the status bar, Tk::after might be what you need.
It allows time delayed callbacks to be made to a particular subroutine. So, you could have a subroutine that checks progress, and updates the status bar variable.
This would be called by the $w->after command. (you can set a reference to the callback and the delay in milliseconds between calls.
The widget example that I referred to is found in the standard distribution. Just in case you can't get your hands on a copy, I'm pasting it in here. Unfortunately, all my scripts that use Tk::ProgressBar are back at home :o) several thousand miles away...
# ProgressBar - display various progress bars.
use strict;
use Tk;
use Tk::ProgressBar;
use Tk::Scale;
my $mw = MainWindow->new;
my $status_var = 0;
my($fromv,$tov) = (0,100);
foreach my $loop (0..1) {
my $res = 0;
my $blks = 10;
my @p = qw(top bottom left right);
foreach my $dir (qw(n s w e)) {
$mw->ProgressBar(
-borderwidth => 2,
-relief => 'sunken',
-width => 20,
-padx => 2,
-pady => 2,
-variable => \$status_var,
-colors => [0 => 'green', 50 => 'yellow' , 80 => 'red'],
-resolution => $res,
-blocks => $blks,
-anchor => $dir,
-from => $fromv,
-to => $tov
)->pack(
-padx => 10,
-pady => 10,
-side => pop(@p),
-fill => 'both',
-expand => 1
);
$blks = abs($blks - ($res * 2));
$res = abs(5 - $res);
}
($fromv,$tov) = ($tov,$fromv);
}
$mw->Scale(-from => 0, -to => 100, -variable => \$status_var)->pack;
MainLoop;
What I'd suggest is that you have a method that updates the variable $status_var in a callback.
ie:
# Your script should have
$MainWindow->after(10,\&update_var);
# this is the update variable callback.
sub update_var {
$status_var = $work_done/$total;
$status_var = $status_var * 100; # get percentage
}
HTH |