lil_v has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'm trying to place a set of label, entry, label, numEntry one after another. I tried all possilibities for Side and Anchor but it just doesnt seem to work! Here is part of my Code: Any suggestions?
#!/usr/bin/perl use Tk; use Tk::NoteBook; use Tk::CollapsableFrame; use Tk::BrowseEntry; use Tk::Dialog; use Tk::NumEntry; use Tk::Pane; $mw = MainWindow->new(); $mw->geometry( "500x700" ); #P140 my $pane4 = $mw->Scrolled( qw/Pane -width 500 -height 100 -scrollbars ow -sticky ne/, )->pack; my $P140 = $pane4->CollapsableFrame(-title => 'P140', + #title of the collapsable frame -height => 500); + #height of the collapsable frame $P140->pack(qw/-fill x -expand 1/); ###VISK0-3 my $cf_visk0 = $P140->Subwidget('colf'); my $base_visk0 = 6.6824; my $power_visk0 = -8; $cf_visk0->Label(-text=>"VISK0") -> pack(-side => 'left', -anchor => 'w'); $cf_visk0->Entry(-textvariable => \$base_visk0, -width => 10)->pack(-side => 'left', -anchor => 'w'); $cf_visk0->Label(-text=>"E") -> pack(-side => 'left'); $cf_visk0->NumEntry(-minvalue => -20, -maxvalue => 10, -textvariable => \$power_visk0, -width=>5)->pack(-side => 'left', -anchor => 'w'); $cf_visk0->Button(-text => "OK", -command => \&options_visk)->pack(-side => 'left', -anchor => 'w'); $cf_visk0->Button(-text => "Help", -command => \&help_visk0)->pack(-si +de => 'right', -an +chor => 'e'); my $cf_visk1 = $P140->Subwidget('colf'); my $base_visk1 = 6.6047; my $power_visk1 = -10; $cf_visk1->Label(-text=>"VISK1") -> pack(-anchor => 'w'); $cf_visk1->Entry(-textvariable => \$base_visk1, -width => 10)->pack(-side => 'left', -anchor => 'w'); $cf_visk1->Label(-text=>"E") -> pack(-side => 'left', -anchor => 'w'); $cf_visk1->NumEntry(-minvalue => -20, -maxvalue => 10, -textvariable => \$power_visk1, -width=>5)->pack(-side => 'left', -anchor => 'w'); $cf_visk1->Button(-text => "OK", -command => \&options_visk)->pack(-side => 'left', -anchor => 'w'); my $cf_visk2 = $P140->Subwidget('colf'); my $base_visk2 = -1.2627; my $power_visk2 = -13; $cf_visk2->Label(-text=>"VISK2") -> pack(-side => 'left', -anchor => 'w'); $cf_visk2->Entry(-textvariable => \$base_visk2, -width => 10)->pack(-side => 'left', -anchor => 'w'); $cf_visk2->Label(-text=>"E") -> pack(-side => 'left', -anchor => 'w'); $cf_visk2->NumEntry(-minvalue => -20, -maxvalue => 10, -textvariable => \$power_visk2, -width=>5)->pack(-side => 'left', -anchor => 'w'); $cf_visk2->Button(-text => "OK", -command => \&options_visk)->pack(-side => 'left', -anchor => 'w'); MainLoop;

Replies are listed 'Best First'.
Re: Side and Anchor???
by jethro (Monsignor) on Jun 23, 2008 at 23:31 UTC
    Can't test your code, but a simple -side=>'left', -expand=>1 (without the anchor) on every widget should put the widgets from left to right.

    If that doesn't work, it should not be because of pack. Maybe substitute CollapsableFrame with a normal Frame and see if it makes a difference.

Re: Side and Anchor???
by Anonymous Monk on Jun 24, 2008 at 10:32 UTC
      sry abt dat, i copied only a part of my code, i 4got 2 define the value again... Then problem i have is, I want to have it in this format:
      line 1 - Label Entry Label NumEntry Button line 2 - Label Entry Label NumEntry Button line 3 - Label Entry Label NumEntry Button line 4 - Button
        Well, I got my wisdom out of the O'Reilly book 'Learning Perl/Tk' (which is out of print, the successor is called 'Mastering Perl/Tk'). Especially if you want to do more with Perl/Tk it might be better to read about it yourself.

        Luckily the chapter about pack is available online: http://oreilly.com/catalog/lperltk/chapter/ch02.html