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; } }

In reply to Re: Updating the Tk::ProgressBar live by pg
in thread Updating the Tk::ProgressBar live by Ace128

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.