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?
In reply to Using a Tk window within a function by axis3x3
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |