The
repeat() call is only there to demo the progress bar; your actual code will probably not need to use
repeat() at all. Write your Perl/TK program as normal, but whenever an event occurs that marks a further step toward the completion of the task, update
$Progress at the end of that event. For example:
use strict;
use warnings;
use Tk;
use Tk::StatusBar;
my $mw = MainWindow->new();
$mw->Label( -text => 'Mission: knock three times' )->pack();
$mw->Button( -text => 'Knock', -command => \&knock )->pack();
my $sb = $mw->StatusBar();
my $Label1 = 'Progress in knocking:';
$sb->addLabel( -textvariable => \$Label1 );
my $Progress = 0;
sub knock {
print "Knocking\n";
$Progress += 33;
$Label1 = 'Done!' if $Progress >= 99;
}
$sb->addProgressBar(
-length => 60,
-from => 0,
-to => 99,
-variable => \$Progress,
);
MainLoop();