in reply to Re^2: Perl Tk unable to return from MainLoop when implemented in a subroutine
in thread Perl Tk unable to return from MainLoop when implemented in a subroutine

I can't replicate your problem. I added use Tk; to the top of the script, and the following to the bottom:
print %{ getSelectedSeq([{ ID => 1, folder => '/' }, { ID => 2, folder => 'home' }], 12)->[0] };

I'm getting the output and the program terminates.

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^4: Perl Tk unable to return from MainLoop when implemented in a subroutine
by ngocanh (Novice) on Mar 23, 2016 at 13:16 UTC

    I have spent more than 1 day on this bug and I have completely no idea why I have this problem. In my program there are also other subroutines which display popup windows but none of them have this problem. I notice that to display other pop-ups I used $main->Show;, probably that's why I never encountered this problem?

    Is there any other way of displaying this selection box without having to write MainLoop; at all? So far I have tried 2 ways as shown in the code but they all hang. I'm using Perl 5.8.4 and I can't install any additional library.

      Try using Tk->exit

Re^4: Perl Tk unable to return from MainLoop when implemented in a subroutine
by ngocanh (Novice) on Mar 24, 2016 at 01:04 UTC

    When I try Tk::exit;, the whole program terminates, not just the GUI :(((

      Ok, stick with dialogs in that case :D
Re^4: Perl Tk unable to return from MainLoop when implemented in a subroutine
by ngocanh (Novice) on Mar 24, 2016 at 01:40 UTC

    Can you enlighten me on how I can use dialog box to do the same purpose? :P

    I wanted to use dialog to do this, but could not find any code example on how :(. If can do this with dialog box it would be great!

      #!/usr/bin/perl -- use strict; use warnings; use Tk; my $omw = tkinit(); $omw->withdraw; ## no show my $theword ; my $mw = $omw->Dialog( -textvariable => \$theword ); $mw->transient(undef); ## let dialog show even if MainWindow withdrawn for my $ix ( 1..3 ){ $theword = "bird " x $ix; print join ' ', scalar(gmtime ), $mw->Show, ## "MainLoop" "\n"; sleep 1; }