in reply to Progress Bars TK::ProgressBars First time trying it..
Tk applications are generally written in an event driven framework - not linearly like many command line programs and CGI programs (let's not talk about sessions) and the vast majority of utility scripts we write. The general formula for written an event driven application in Tk is like so:
An event driven program creates a framework for a user to do something then waits around for that user to do it. For example:# psuedo-code Initialization; Create main widget; Create child widgets; MainLoop; exit; Callbacks that do stuff;
Here I initialize my code and once I have my widgets done I call MainLoop. Now the program sits there and waits for an event (a button press in this case). When the event is recieved it performs a task - in this case one that is defined in the subroutine named do_me (I have to work on my naming conventions...). The program stays within the MainLoop part of the code until it exits or is terminated.#! /usr/bin/perl -w use strict; use Tk; use Tk::DialogBox; use Tk::ProgressBar; my $w = new MainWindow(-title => 'Demo Tk'); my $pb = $w->ProgressBar( -width => 15, -length => 100, -from => 0, -to => 19 )->pack; $w->Button(-text => 'Push me', -command => [ \&do_me, $w, $pb ])->pack +; MainLoop; exit; sub do_me { my $w = shift; my $pb = shift; for (0..19) { $pb->value($_); $w->update; sleep(1) } }
In your case it would require a bit of re-working what you have to work in this kind of framework. You have all the pieces but you would want to stick all of your job processing into a do_me style subroutine. Then as you complete each job increment the value of your progress widget and update the window.
When I was first learning event driven programming it took me a while to 'get it'. I'm afraid I still can't explain it very well, but hopefully others will chip in here. I also expound endlessly on the subject in this node.
Good luck,
{NULE}
--
http://www.nule.org
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Progress Bars TK::ProgressBars First time trying it..
by Rhodium (Scribe) on Apr 22, 2002 at 20:01 UTC |