Hi Rhodium,

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:

# psuedo-code Initialization; Create main widget; Create child widgets; MainLoop; exit; Callbacks that do stuff;
An event driven program creates a framework for a user to do something then waits around for that user to do it. For example:
#! /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) } }
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.

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


In reply to Re: Progress Bars TK::ProgressBars First time trying it.. by {NULE}
in thread Progress Bars TK::ProgressBars First time trying it.. by Rhodium

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.