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

Hello, I'm writing a script that needs a progress bar that goes back to 0 (at the beginning of each file being parsed in, obviously ;-), but cannot find any way to get the progress bar to restart itself. I have tried many methods, none of which have worked. I'll update this post with my code if necessary, but I'm using the code straight from the user docs, and all the variations I've tried would take three or four screen scrolls....

The best I've been able to get is a single progress bar that goes to and just stays at 100%, and the worst is multiple bars that pop in one under another, still at 100%, or no progress bars at all; it depends on how you look at it as to which is worse...

I've tried resetting the init values with $pb->configure() but I get a "tied" error and perl exits...
<snip>

untie attempted while 1 inner references still exist at C:/Perl/site/l +ib/Tk/ProgressBar.pm line 306. Can't call method "pack" on unblessed reference at myscript.pl line 43 +6.
</snip>

Any advice, hints, pointers appreciated...

Thank you,
amonotod

Replies are listed 'Best First'.
Re: Tk::ProgressBar --Reset it?
by bbfu (Curate) on Jul 08, 2004 at 23:24 UTC

    I tried the following and it worked just fine:

    #!/usr/bin/winperl use warnings; use strict; use Tk; use Tk::ProgressBar; my $w = MainWindow->new(); my $p = $w->ProgressBar( -blocks => 1, -width => 20, -length => 200, -from => 0, -to => 100, -variable => \(my $foo), )->pack(); $foo = 0; $w->repeat(10, sub { $foo = ($foo + 1) % 100 }); MainLoop;

    bbfu
    Black flowers blossom
    Fearless on my breath

      Here is the now working code that is closer to what I am doing...
      #perl -w use strict; my ($display, $progress, $percent_done, $progress_bar_set, $mw, $lblTe +xt, $display, $line, $count); &CreateDisplay; $line = 1; while ($line < 30) { $display->insert('0.0', "Line $line\n"); $mw->update; $count = 1; while ($count < 50) { $percent_done = $count * 2; $mw->update; $count++; sleep 1; } $line++; sleep 2; } sub CreateDisplay { use Tk; use Tk::Text; $mw = MainWindow->new(-title => 'Progress bars'); create_progressbar(); $lblText = $mw->Label(-text=>"This is a test of multiple progress ba +rs...")->pack(-side => 'top'); $display = $mw->Text(-height => '25', -width => '100',)->pack(-side +=> 'bottom', -expand => '1', -fill => 'both'); $display->insert('0.0', "Starting line\n"); $mw->update; } sub create_progressbar { use Tk::ProgressBar; $progress = $mw->ProgressBar( # create a progress bar for reference -length => 100, -width => 20, -from => 0, -to => 100, -blocks => 100, -colors => [0, 'blue'], -variable => \$percent_done )->pack(-fill => 'x'); }
      The missing ingredient was the the $mw->update after each $percent_done incremement. It worked while increasing, but just didn't when decreasing, for some reason.....

      Thank you for the help,
      amonotod

Re: Tk::ProgressBar --Reset it?
by Ven'Tatsu (Deacon) on Jul 08, 2004 at 21:04 UTC
    Can you post the code you use to create, update, and your attempt to reset the progress bar?