I've only done a little programming with Perl/Tk, although I've been programming with perl for quite a while. Hence, I'm having a little trouble with the 'event-driven' thing.
The attached code does what it does... but instead of clicking the "Pop It!" button to bring up the popup window, I actually want the sequence of things to be more like:
- setup the main window
- click the "Pop It!" button and call 'AddItem'
- once in AddItem, I want the popup to be displayed, and to stay there whilst I do things in 'AddItem'. Once 'AddItem' is more-or-less done, the popup is removed (like when the button is pressed) and we're back in the main window.
The popup is like a 'status' window... but I'm not sure how to actually -do it-... It's simple enough to do things with a button action but this is where I get confused with the 'event-driven' thing.
I'd appreciate any pointers...
Thanks.
John
use strict; use Tk; my $mw = MainWindow->new; # Main window my $top = $mw->Frame( -background => '#239867', -borderwidth => 2, )->pack(-fill => 'both'); my $lbltxt = $top->Label( -text => 'Just some text', -background => 'white', )->pack(-side => 'right', -padx => 10); my $GoBtn = $top->Button( -text => ' Pop It! ', -command => \&AddItem )->pack(-side => 'left', -padx => 10, -pady => 5); my $DoneBtn = $top->Button( -text => ' Exit ', -command => \&Cleanup )->pack(-side => 'right', -padx => 10, -pady => 5); $mw->focus; # Ensure we're talking to the main window MainLoop; # Run the program, watching for events # ---- sub Cleanup { $mw->destroy; } # ---- sub AddItem { my $tp = $mw->Toplevel( -title => ' AddItem' ); # ->pack(-fill => 'both'); my $tpfrm = $tp->Frame( -background => '#22cc00', )->pack(-side => 'top', -fill => 'x'); my $tplbl = $tpfrm->Label( -text => 'Working...', -background => 'white', -foreground => 'black' )->pack(-side => 'top', -padx => 10); my $tpbtn = $tpfrm->Button( -text => 'Close', -command => [$tp => 'destroy'], )->pack(-side => 'top', -padx => 10, -pady => 5); }
In reply to How to PopUp a 'Status' window in Perl/Tk by ozboomer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |