Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I want to write a small tk program with a progress bar. The initial value should be 30 and the program should quit automatically when the value is 90.
Each second the value of the progress bar shall be increased by one.
The stuff with the increasing I do with repeat.
My big probem is that the anonymous function within the repeat does not get the initial value of the variable $nb_sec. It is even undefined
Here the error message:
Use of uninitialized value $nb_sec in addition (+) at c:/pb_test.pl line 24.Here you can see my code:
use strict; use warnings; use Tk; use Tk::ProgressBar; my $nb_sec = 30; my $mw = MainWindow->new(-title => 'Progress Bar Example'); $mw->resizable(0,0); my $pb = $mw->ProgressBar(-from => 0, -to => 90, -blocks => 90, -anchor => 'w', -length => 200, -width => 30, -colors => [0,'blue'], -variable => \$nb_sec)->pack(); $pb->repeat( 1000 => sub { $nb_sec += 1; $mw->destroy if $nb_sec >= 90; }); MainLoop();
And another question: What would be the best way to update a label each second to show the current value of the progress bar? Would you take the configure method?
Thank you for your help.
Dirk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: TK: Repeat and variable from outside
by lamprecht (Friar) on Apr 04, 2011 at 15:11 UTC |