I'm fairly new to using Perl/Tk, although I've been using perl for quite a few years.
I would like to build a series of prompt labels and entry fields on a single window in a format like:
Name: ____________________
Version: __________
Description: ________________________________________
Date: __________
(I want the colons to line-up vertically and the whole thing to be centred in the window).
The code is included at the bottom of this post.
The use of pack() seems to be non-intuitive to me, once you get more than one widget in a frame.
If someone could explain what I'm doing wrong, I'd be very appreciative.
I'm using ActiveState Perl v5.6.1, build 628, Perl/Tk version 800.022 on Windows 98 SE (OEM).
Many thanks for any forthcoming suggestions.
John
use strict; use Tk; my $mw = MainWindow->new; # Main window $mw->geometry('532x432+100+200'); $mw->resizable(0, 0); # ...no re-sizing # ------------------------------------- # Create frames for widgets # my $hdrfrm = $mw->Frame( # The Top 'Bar' -background => 'magenta', -height => 10, )->pack(-side => 'top', -fill => 'x'); # , -pady => 5); my $entryfrm = $mw->Frame( # The Middle 'Bar' -background => 'cyan', -width => 200, -height => 200, )->pack(-side => 'top', -fill => 'x'); my $btnfrm = $mw->Frame( # The Button 'Bar' -background => 'darkgrey', # -height => 30, )->pack(-side => 'top', -fill => 'x'); # , -pady => 5); # ------------------------------------- # Place buttons # my $AddBtn = $btnfrm->Button( # 'Add' -text => ' Add ', -command => [$mw => 'destroy'] )->pack(-side => 'left', -padx => 10, -pady => 5); my $RptBtn = $btnfrm->Button( -text => 'Report', -command => [$mw => 'destroy'] )->pack(-side => 'left', -padx => 5, -pady => 5); my $AboutBtn = $btnfrm->Button( -text => 'About', -command => [$mw => 'destroy'] )->pack(-side => 'left', -padx => 100); my $DoneBtn = $btnfrm->Button( -text => ' Done ', -command => [$mw => 'destroy'] )->pack(-side => 'right', -padx => 10, -pady => 5); # ------------------------------------- # Place prompt labels and fields # my $pmt2 = $entryfrm->Label( # Name -text => 'Name:', -background => 'magenta', )->pack(-side => 'left'); # , -anchor => 'n'); my $fld2 = $entryfrm->Entry( -relief => 'sunken' )->pack(-side => 'left'); # , -anchor => 'nw'); my $pmt3 = $entryfrm->Label( # Version -text => 'Version:', -background => 'magenta', )->pack(-side => 'left'); my $fld3 = $entryfrm->Entry( -relief => 'sunken' )->pack(-side => 'left'); my $pmt4 = $entryfrm->Label( # Description -text => 'Description:', -background => 'magenta', )->pack(-side => 'top'); my $fld4 = $entryfrm->Entry( -relief => 'sunken' )->pack(-side => 'top'); MainLoop;
In reply to Perl/Tk: Need Assistance with use of pack() by ozboomer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |