Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am using the use Tk::StatusBar for show the status. Given example in that module showinng continues repeat. can i increment the status bar with out using repeat method. because i can not write my entire code in repeat function
use strict; use warnings; use Tk; use Tk::StatusBar; my $mw = new MainWindow; my $Label1 = "Welcome to the statusbar"; my $Label2 = "On"; my $Progress = 0; my $sb = $mw->StatusBar(); $sb->addLabel( -relief => 'flat', -textvariable => \$Label1, ); my $p = $sb->addProgressBar( -length => 60, -from => 0, -to => 100, -variable => \$Progress, ); $mw->repeat('50', sub { $Progress = 0 if (++$Progress > 100); }); MainLoop();

Replies are listed 'Best First'.
Re: How to use Tk::StatusBar
by Util (Priest) on Oct 27, 2008 at 13:16 UTC
    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();
Re: How to use Tk::StatusBar
by Anonymous Monk on Oct 27, 2008 at 07:00 UTC
    What is stopping you?