Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Using Tk::ProgressBar

by radiantmatrix (Parson)
on Oct 28, 2005 at 14:27 UTC ( #503659=note: print w/replies, xml ) Need Help??

in reply to Using Tk::ProgressBar

There are a couple of approaches here. All of them require an understanding that MainLoop is just an event loop. That means factoring your code in such a way that it does small chunks of operation at a time. For example:

#instead of: for (1..100000) { sleep 1; } $mw->update(); #do for (1..100000) { sleep 1; $pb->update($_); #update progressbar $mw->upddate(); }

One approach is to make a progress bar in your MainWindow, then when finished delete the bar and populate the MainWindow with the widgets that display your results.

Another is to have a "status bar" type area in your results window, show your results window immediately, but with all but the status bar "greyed out" (disabled) until you finish calculating results.

Both of the above only require one MainLoop.

Another approach, and one I'm a big fan of, is to refactor your application as a POE app, and use POE's event loop (which encapsulates a Tk event loop) to manage the various components of your application.

All that said, there is no reason your result window has to be the MainWindow. You could just as easily create a sub window that's displayed near the end of the MainLoop.

How about some code you've tried?

A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://503659]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-06-22 23:00 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (110 votes). Check out past polls.