Great Monks,

I'm new to Perl/Tk. I've read as much documentation as I can: browsing the modules on CPAN, using SuperSearch, Google, PerlDoc.com, and the Perl Cookbook. I must be missing something.

I'm attempting to write an application that does not require input from the user (beyond invocation), but displays a progress bar (I'm using Tk::ProgressBar ) and some status text while it works. I've had success initiating all of the action and output if I give the user a 'Start' button. However, this needs to be suitable for automation.

It seems that if I put my logic before MainLoop, nothing displays until my logic is complete. MainLoop blocks, so I can't flow code after it. The only way I've found to invoke any code after the call to MainLoop is to have the user click a Widget to invoke a callback.

Update {
Found a solution, thanks to Ven'Tatsu: it works, is there anything better, or caveats I should be aware of?

#this is psuedo-codeish use Tk; my $mw = new Tk::MainWindow; my $p_bar = $mw->ProgressBar; # No longer needed: # my $button = $mw->Button(-command=>\&main_logic, -text=>'start'); # $button->pack(); $p_bar->pack(); #this is the solution, thanks to Ven'Tatsu: $mw->after(0,\&main_logic); MainLoop; sub main_logic { # $button->configure(-state=>"disabled"); for (...) { # do some stuff... $p_bar->value($pct_complete); $mw->update(); } $mw->destroy; }
What I'm essentially trying to do is eliminate the need to push the button.
}

Is there any way to cause a Tk::MainWindow to display and immediately invoke a callback?

--
$me = rand($hacker{perl});

All code, unless otherwise noted, is untested
"All it will give you though, are headaches after headaches as it misinterprets your instructions in the most innovative yet useless ways." - Maypole and I - Tales from the Frontier of a Relationship (by Corion)

In reply to Creating a non-UI event in Perl/Tk by radiantmatrix

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.