Tk's binding the -variable seems to reset it. Workaround is easy: Set the initial value after instantiation of your ProgressBar.
use strict;
use warnings;
use Tk;
use Tk::ProgressBar;
my $nb_sec;
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();
$mw->Label(-textvariable => \$nb_sec)->pack;
$nb_sec = 30;
$pb->repeat(
1000 => sub
{
$nb_sec += 1;
$mw->destroy if $nb_sec >= 90;
});
MainLoop();
Cheers, Christoph