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

I have defined a main window with Lable,Entry Text Box and Command Button.

Below is the code I have written: my $input='Enter the site address..';
my $mw = new MainWindow;
my $label =$mw -> Label(-text=>"Site Address") -> pack(-pady=>5,-side=>'left');
my $text =$mw ->Entry(-width=>100,-textvariable=>\$input,-state=>"normal")->pack(-padx=>15,-side=>'right');
my $button = $mw -> Button(-text => "Quit", -command => sub { exit })-> pack(-anchor=>'center',-pady=>30,-padx=>100);
MainLoop;

On execution of above code the command button is placed inbetween Lable and entry field.I want to place the command button below the label and entry field.

Replies are listed 'Best First'.
Re: Specifying the Position of widget
by zentara (Cardinal) on Mar 30, 2009 at 11:32 UTC
    Please put your code in code tags, it makes it easier for us.

    Anyways....you use frames. You can nest frames very deeply to get a nice organized window, that expands/contracts nicely.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $input='Enter the site address..'; my $mw = new MainWindow; my $topframe = $mw->Frame()->pack(-expand=>1, -fill=>'both'); my $botframe = $mw->Frame()->pack(-fill=>'x'); my $label = $topframe->Label( -text => "Site Address" ) ->pack( -pady => 5, -side => 'left' ); my $text = $topframe->Entry( -width => 100, -textvariable => \$input, -state => "normal" ) ->pack( -padx => 15, -side => 'right' ); my $button = $botframe->Button( -text => "Quit", -command => sub { exi +t } ) ->pack( -side => 'right', -padx=> 10); MainLoop;

    I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
Re: Specifying the Position of widget
by Marshall (Canon) on Mar 30, 2009 at 18:15 UTC
    One book that helped me was: Learning Perl/Tk by Nancy Walsh.

    There are 3 geometry managers in Tk: pack, place and grid. The most common is pack.

    A "frame" is like a sub-area of a window. You can "pack" things into frames and frames into windows or other frames. To make 2 widgets appear above one another, make a frame, then "pack" the 2 widgets into that frame. A "Frame" is like a sub-set rectangle of a window but without visible borders.

    A "gui builder" is not necessary with Tk. The easy way is to draw by hand what you are trying to create. Use pencil and paper! Draw a line around each widget. Then draw the frames. This mainly has to do with the vertical placement of groups of widgets along a "row".

    There are other GUI's that I've heard about for Perl. But Tk works well.

      and Tk::form which can be very nice for laying out windows containing multiple controls, some of which resize as the window resizes.


      True laziness is hard work
        This looks very nice. Thanks!! I've got a new project coming up that will need some stuff like this! Users like re-sizing, but its hard to do. I hope all this helped the original poster.