First, the minor bugs and questionable code; here is a diagram of your control tree:

# MainWindow $MW # Frame Frame1 # Labelframe SourceFrame # Label SourceTypeLabel # Optionmenu SourceTypeMenu # Frame sourceoneFrame # Mutually exclusive # Frame sourcetwoFrame # Mutually exclusive # Label StringLabel

To fix the abort, I reached the same conclusion that you did; wrap sub{ } around the value side of

-command => $typeframes{'source'}->{ $config{'sourcetype'} }->( \%tkobjects ),
Why did the original version fail? Because -command expects a coderef, but your code is an *immediate* call to
(Let's see: $config{'sourcetype'} is 'one', and $typeframes{'source'}->{'one'} is &makeSourceoneFrame, so ...)
makeSourceoneFrame(\%tkobjects), which returns a Label object. When Tk tries to call the Label as a coderef, boom!

By wrapping it all in sub{ }, you create a closure where (for example) $config{'sourcetype'} will supply its hash value as of the time of invocation, instead of at the time of definition. See perlfaq7 and perlref for more on closures.

When I refactored the code to reflect the closure, I came up with this version; it replaces the code just before MainLoop:

# $option_command will be an anon sub, # with sole access to %typeframes. my $option_command; { my %typeframes = ( 'source' => { 'one' => \&makeSourceoneFrame, 'two' => \&makeSourcetwoFrame, } ); $option_command = sub { my $option = shift; $typeframes{'source'}->{ $option }->( \%tkobjects ); } } $tkobjects{'SourceTypeMenu'} = $tkobjects{SourceFrame}->Optionmenu( # -variable => \$config{'sourcetype'}, # No longer needed! -command => $option_command, -options => \@TYPES )->grid( -row => 1, -column => 1, ); # By naming the anon sub (via variable), we avoid # repeating code here. $option_command->('one'); # Actually, we don't have to manually invoke $option_command; # it got called with the first (default) option when # the OptionMenu was created! MainLoop;


In reply to Re: Tk destroy method dies with "Aborted" by Util
in thread Tk destroy method dies with "Aborted" by g0n

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.