axis3x3 has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks, I want to use a Tk window to ask a user a question inside a function, and then return their answer as the return value.
Previously, I had code like this:
sub ask( $ ) { my $question = shift; my $textbox; $main_window = MainWindow->new; $main_window->title("Question"); $main_window->minsize(qw(400 250)); $main_window->geometry('+250+150'); $top_frame = $main_window->Frame()->pack; $middle_frame = $main_window->Frame()->pack; $bottom_frame = $main_window->Frame()->pack(-side => 'bottom'); $top_frame->Label(-height => 2)->pack; $top_frame->Label(-text => $question)->pack; $bottom_frame->Button(-text => "OK", -command => sub { goto(answer_ok2) }, -width => 10 )->pack(-padx => 2, -pady => 4); $textbox = $middle_frame->Entry(-show => $show)->pack(); MainLoop(); answer_ok2: my $ans = $textbox->get(); $main_window->destroy; return $ans; }
but this desn't work with Tk 804, so I need a better way of doing it.
The above method makes me feel dirty as we are still inside that MainLoop call when we return.
Is there some way to exit from MainLoop once it's started, or is there another cludge I can use?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using a Tk window within a function
by bbfu (Curate) on May 27, 2004 at 19:19 UTC | |
by axis3x3 (Acolyte) on May 27, 2004 at 19:42 UTC | |
|
•Re: Using a Tk window within a function
by merlyn (Sage) on May 27, 2004 at 18:55 UTC | |
by axis3x3 (Acolyte) on May 27, 2004 at 18:57 UTC | |
|
Re: Using a Tk window within a function
by zentara (Cardinal) on May 28, 2004 at 15:13 UTC | |
by Anonymous Monk on May 28, 2004 at 18:00 UTC | |
by axis3x3 (Acolyte) on May 28, 2004 at 18:07 UTC | |
by zentara (Cardinal) on May 29, 2004 at 13:22 UTC | |
|
Re: Using a Tk window within a function
by Anonymous Monk on May 28, 2004 at 18:02 UTC |