http://www.perlmonks.org?node_id=518829

bibliophile has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks,

I'm trying to have a Perl/Tk application create menus on the fly, depending on current state. This works... mostly. When I exit the application, I get an error message along the following lines:

18e6748 is not a hash at C:/Perl/site/lib/Tk.pm line 340. This application has requested the Runtime to terminate it in an unusu +al way. Please contact the application's support team for more information.
I've been able to reproduce this with a minimalist example:
#!/usr/bin/perl use Tk; my $mw = MainWindow->new; my $txt = $mw->Text()->pack(-side => 'top'); my $number = 1; my $letter = 'a'; my $popup_menu = ""; my $new_menu = $mw->Menu(); $new_menu->add('command', -label => "Click me to show the pop-up menu.", -command => sub { $popup_menu = $mw->Menu(); $popup_menu->add('command', -label => "Number: $number", -command => sub { print STDERR "Number: $number\n"; $number++; } ); $popup_menu->add('command', -label => "Letter: $letter", -command => sub { print STDERR "Letter: $letter\n"; $letter++; } ); $popup_menu->Popup(qw/-popover cursor/); } ); $txt->menu( $new_menu ); MainLoop;
Doing a SuperSearch for keywords "application requested Runtime terminate unusual" didn't turn up anything.

I'm sure I am not understanding some fundamental Tk concept here... can anyone point me in the right direction?

-- -David

Replies are listed 'Best First'.
Re: Dynamic menus in Perl/Tk giving error
by BrowserUk (Patriarch) on Dec 23, 2005 at 21:10 UTC

    Which versions of Perl, Tk, and OS are you running?

    Your snippet runs and exits clean on my system. (XP/AS815/804.027).


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I'm running ActiveState Perl 5.8.2 on WinXP SP2:

      C:\wrk\hmm>perl -v This is perl, v5.8.2 built for MSWin32-x86-multi-thread (with 25 registered patches, see perl -V for more detail) Copyright 1987-2003, Larry Wall Binary build 808 provided by ActiveState Corp. http://www.ActiveState. +com ActiveState is a division of Sophos. Built Dec 9 2003 10:19:40
      Oop: and...
      C:\wrk\Tk-MARC_Editor-0.5>perl -e "use Tk; print $Tk::version . $/;" 8.0
      -- David

        That your snippet runs clean here would tend to indicate that there is nothing wrong with your code; which leaves you in the position of deciding what you should upgrade to fix the problem.

        As AS Perl comes with Tk, if upgrading Perl is an option for you, that would probably be the path of least resistance. I've successfully installed the last half dozen AS binary distributions over the top of their predecessors, thus avoiding having to re-build/reinstall all the modules I've added to my distribution, and have yet to find a binary incompatibility. However, I do not run any "production code", or anything vital to me.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.