#!/usr/bin/perl use strict; use Tk; our ($goMainWindow); our (%ghGuiObjs); our (%ghGuiCBVars); $| = 1; &main(); sub main { buildGui(); MainLoop; } #end sub main sub updateA { if ( $ghGuiCBVars{"nEnableFrameA"} == 1 ) { $ghGuiObjs{"oContainerA"}->pack(); } else { $ghGuiObjs{"oContainerA"}->packForget(); } } sub updateB { if ( $ghGuiCBVars{"nEnableFrameB"} == 1 ) { $ghGuiObjs{"oContainerB"}->pack(); } else { $ghGuiObjs{"oContainerB"}->packForget(); } } sub buildGui { $goMainWindow = new MainWindow; my ($oLabel) = $goMainWindow->Label( -text => "This is my example", )->pack( -padx => '5', -pady => '5', -expand => '1', -fill => 'x', ); my ($oCbA) = $goMainWindow->Checkbutton( -text => 'Enable A', -variable => \$ghGuiCBVars{"nEnableFrameA"}, -command => \&updateA, -anchor => 'w', ); $ghGuiCBVars{"nEnableFrameA"} = 1; my ($oFrameA) = $goMainWindow->Labelframe( -labelwidget => $oCbA, )->pack( -padx => '5', -expand => '1', -fill => 'both', ); my ($oContainerFrameA) = $oFrameA->Frame( )->pack( -expand => '1', -fill => 'both', -pady => '5', ); $ghGuiObjs{"oContainerA"} = $oContainerFrameA; my ($oLbA) = $oContainerFrameA->Listbox( -relief => 'groove', -borderwidth => '5', -height => '5', )->pack( -fill => 'both', -expand => '1', ); my ($oCbB) = $goMainWindow->Checkbutton( -text => 'Enable B', -variable => \$ghGuiCBVars{"nEnableFrameB"}, -command => \&updateB, -anchor => 'w', ); $ghGuiCBVars{"nEnableFrameB"} = 1; my ($oFrameB) = $goMainWindow->Labelframe( -labelwidget => $oCbB, )->pack( -padx => '5', -expand => '1', -fill => 'both', ); my ($oContainerFrameB) = $oFrameB->Frame( )->pack( -expand => '1', -fill => 'both', -pady => '5', ); $ghGuiObjs{"oContainerB"} = $oContainerFrameB; my ($oLbB) = $oContainerFrameB->Listbox( -relief => 'groove', -borderwidth => '5', -height => '5', )->pack( -fill => 'both', -expand => '1', ); my ($oExit) = $goMainWindow->Button(-text => 'Exit', -command => sub{exit}, )->pack( -padx => '5', -pady => '5', -side => 'bottom', ); }