#!/usr/bin/perl -w # Strict use strict; use warnings; # Libraries use Tk; use Tk::Pane; use Tk::NoteBook; # Main Program # # Create the GUI, and the top frame my $mw = new MainWindow(); my $top = make_frame($mw, 'white', 'noscroll', 'top', 1, 'both'); # Notebook and notebook pages my $nb = $top->NoteBook()->pack(-expand => 1, -fill => 'both'); my $pg1 = $nb->add('page1', -label => 'Unscrolled'); my $pg2 = $nb->add('page2', -label => 'Scrolled'); # Create subframes (scrolled vs. non-scrolled) my $f1 = make_frame($pg1, 'green', 'noscroll', 'top', 0, 'both'); my $f2 = make_frame($pg2, 'blue', 'scrolled', 'top', 0, 'both'); # Populate frames with subframe containing a label and a button. # Attempt to pack the subframe into the "top" of the containing widget. label_button_frame($f1, 'gold'); # Packs as expected label_button_frame($f2, 'red'); # Fails to pack nicely?? # Manage gui MainLoop; # Subroutines sub make_frame { my ($parent, $bgcolor, $scrolled, $side, $expand, $fill) = @_; my $b_scr = ($scrolled eq 'scrolled')? 1: 0; my $frame = $b_scr? $parent->Scrolled('Frame'): $parent->Frame(); $frame->configure(-bg => $bgcolor); $frame->pack(-side => $side, -expand => $expand, -fill => $fill); return $frame; } sub label_button_frame { my ($parent, $bgcolor) = @_; my $mw = $parent->toplevel(); my $fr = make_frame($parent, $bgcolor, 'noscroll', 'top', 1, 'x'); $fr->configure(-relief => 'groove', -borderwidth => 4); $fr->Label(-text => 'My Label', -rel => 'groove')->pack(-side => 'left'); my $pcmd = sub { $mw->destroy }; $fr->Button(-text => 'Exit', -command => $pcmd)->pack(-side => 'right'); return $fr; }