Aborted #### #!/usr/bin/perl use strict; use warnings; use Tk; main(); ######################################################################################## # main ######################################################################################## sub main { my %tkobjects; # mainwindow my $MW; # # User-defined variables (if any) # my @TYPES = qw(one two); my %config = ( 'sourcetype' => "one" ); my %typeframes = ( 'source' => { 'one' => \&makeSourceoneFrame, 'two' => \&makeSourcetwoFrame } ); ###################### # # Create the MainWindow # ###################### $MW = MainWindow->new; # Widget Frame1 isa Frame $tkobjects{'Frame1'} = $MW->Frame()->grid( -row => 2, -column => 0, -sticky => 'e', ); ######################################################################### # source frame ######################################################################### # Widget SourceFrame isa Labelframe $tkobjects{'SourceFrame'} = $tkobjects{Frame1}->Labelframe( -text => 'Source' )->grid( -row => 1, -column => 0, -sticky => 'ns', ); # Widget SourceTypeLabel isa Label $tkobjects{'SourceTypeLabel'} = $tkobjects{SourceFrame}->Label( -text => 'Type', )->grid( -row => 1, -column => 0, ); # Widget SourceTypeMenu isa Optionmenu $tkobjects{'SourceTypeMenu'} = $tkobjects{SourceFrame}->Optionmenu( -variable => \$config{'sourcetype'}, -command => $typeframes{'source'}->{ $config{'sourcetype'} }->( \%tkobjects ), -options => \@TYPES )->grid( -row => 1, -column => 1, ); $typeframes{'source'}->{ $config{'sourcetype'} }->( \%tkobjects ); ############### # # MainLoop # ############### MainLoop; } ######################################################################### # make source one frame ######################################################################### sub makeSourceoneFrame { my $tkobjectsref = shift; my %tkobjects = %$tkobjectsref; # if switching to one, destroy the twoframe if ( $tkobjects{'sourcetwoFrame'} ) { $tkobjects{'sourcetwoFrame'}->destroy; } $tkobjects{'sourceoneFrame'} = $tkobjects{'SourceFrame'}->Frame()->grid( -row => 2, -column => 0 ); # Widget SourceSelectString isa Label $tkobjects{'StringLabel'} = $tkobjects{SourceFrame}->Label( -text => "string two", )->grid( -row => 3, -column => 0, ); } ######################################################################### # make source two frame ######################################################################### sub makeSourcetwoFrame { my $tkobjectsref = shift; my %tkobjects = %$tkobjectsref; # if switching to two, destroy the one frame if ( $tkobjects{'sourceoneFrame'} ) { $tkobjects{'sourceoneFrame'}->destroy; } $tkobjects{'sourcetwoFrame'} = $tkobjects{'SourceFrame'}->Frame()->grid( -row => 2, -column => 0 ); $tkobjects{'StringLabel'} = $tkobjects{SourceFrame}->Label( -text => "string two", )->grid( -row => 3, -column => 0, ); }