# MainWindow $MW # Frame Frame1 # Labelframe SourceFrame # Label SourceTypeLabel # Optionmenu SourceTypeMenu # Frame sourceoneFrame # Mutually exclusive # Frame sourcetwoFrame # Mutually exclusive # Label StringLabel #### -command => $typeframes{'source'}->{ $config{'sourcetype'} }->( \%tkobjects ), #### # $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;