ngocanh has asked for the wisdom of the Perl Monks concerning the following question:
This code works fine on its own, after clicking the button, I am able to execute the print statements after MainLoop;. However, when I use this code (without the first 3 lines of course) in a subroutine called in my program, clicking the button only closes the GUI window, anything below the MainLoop; statement is not executed. The whole program just hangs as the subroutine is stuck in the MainLoop. Any suggestion of what I might have done wrong and how can I fix this? Thanks.#!/mu/bin/perl use Tk; use strict; use warnings; my @selections; my @choices = ("choice1", "choice2", "choice3", "choice4", "choice5", +"choice6", "choice7", "choice8"); my $mw = MainWindow->new(-title=>"ListBox"); $mw->Label(-text => 'Select your choices')->pack(); my $lb = $mw->Listbox(-selectmode => 'extended'); $lb->insert('end', sort @choices);$lb->pack(); $mw->Button(-text => 'Select', -command => sub {@selections = $lb->curselection;$m +w->destroy;})->pack(); MainLoop; foreach (@selections) { print $_."\n"; }
|
|---|