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?
What I'm essentially trying to do is eliminate the need to push the button.#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; }
Is there any way to cause a Tk::MainWindow to display and immediately invoke a callback?
In reply to Creating a non-UI event in Perl/Tk by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |