in reply to Updating the Tk::ProgressBar live

That repeat in your code does not work properly, and it does not really make sense to increment progress by 1 every 500 ms, as if you know how long it takes the recursive task to complete. As it is recursive, it is kind of tricky to calculate the progress, as you probably even do not know the size of the entire work. Assume you can, then every time after you calculate the prgress, call update.

use Tk; use Tk::ProgressBar; my $mw = MainWindow->new(); my $value = 1; $mw->Button(-text => "Add/Update!", -command => [\&addUpdateButtonPres +sed])->pack(); $progressBar = $mw->ProgressBar( -width => 16, -length => 400, -anchor => 'w', -from => 0, -to => 10, -blocks => 10, -gap => 0, -colors => [0, 'green', 50, 'yellow' , 80, 'red'], -variable => \$value )->pack(); MainLoop; sub addUpdateButtonPressed { while (1) { $value ++; $progressBar->update(); ($value < 10) ? sleep 1 : last; } }

Replies are listed 'Best First'.
Re^2: Updating the Tk::ProgressBar live
by Ace128 (Hermit) on Sep 06, 2005 at 01:53 UTC
    I do the recursive thing twice. Once to count files. Next to actually do something! (I actually got 2 seperate recursive functions for this purpose) Also, the "recursive" function calls itself when a new dir is found.