#!/usr/bin/perl use strict; use Tk; our ($goMainWindow); our (%ghGuiObjs); our (%ghGuiCBVars); my ($w,$h); $| = 1; &main(); sub main { buildGui(); MainLoop; } #end sub main sub updateA { if ( $ghGuiCBVars{"nEnableFrameA"} == 1 ) { $ghGuiObjs{"oContainerA"}->pack( -expand => '1', -fill => 'both', -pady => '5', ); $goMainWindow->geometry($w.'x'.$h); $goMainWindow->update; } else { $ghGuiObjs{"oContainerA"}->packForget(); } } sub updateB { if ( $ghGuiCBVars{"nEnableFrameB"} == 1 ) { $ghGuiObjs{"oContainerB"}->pack( -expand => '1', -fill => 'both', -pady => '5', ); } else { $ghGuiObjs{"oContainerB"}->packForget(); } } sub buildGui { $goMainWindow = new MainWindow; # $goMainWindow->geometry('200x300'); my ($oExit) = $goMainWindow->Button(-text => 'Exit', -command => sub{exit}, )->pack( -padx => '5', -pady => '5', -side => 'bottom', ); my $mf = $goMainWindow->Frame->pack( -expand => '1', -fill => 'both', -pady => '5', ); my ($oLabel) = $mf->Label( -text => "This is my example", )->pack( -padx => '5', -pady => '5', -expand => '1', -fill => 'x', ); my ($oCbA) = $mf->Checkbutton( -text => 'Enable A', -variable => \$ghGuiCBVars{"nEnableFrameA"}, -command => \&updateA, -anchor => 'w', ); $ghGuiCBVars{"nEnableFrameA"} = 1; my ($oFrameA) = $mf->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) = $mf->Checkbutton( -text => 'Enable B', -variable => \$ghGuiCBVars{"nEnableFrameB"}, -command => \&updateB, -anchor => 'w', ); $ghGuiCBVars{"nEnableFrameB"} = 1; my ($oFrameB) = $mf->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', ); $goMainWindow->idletasks; $w = $goMainWindow->reqwidth; $h = $goMainWindow->reqheight; print "$w $h\n"; #$goMainWindow->minsize($w,$h); }