And here's a version with ->grid using -sticky => 'e' to right justify the labels.
Note no -anchor needed.
#!/usr/bin/perl # http://perlmonks.org/?node_id=1185225 use strict; # module to must always declare variables before you + use them use warnings; # module to show where is the error use Tk; # module for the Windows GUI my $mainwindow = MainWindow->new(); $mainwindow->geometry("600x150"); $mainwindow->title("Window"); # Disable the window Resize $mainwindow->resizable(0,0); # Menu display option my $main_menu = $mainwindow->Menu(); $mainwindow->configure(-menu => $main_menu); #File my $file_menu = $main_menu->cascade(-label=>"File", -underline => 0, - +tearoff=>0); $file_menu->command(-label=>"New", -underline=>0, -command=>sub{exit}, -state => 'disabled'); $file_menu->command(-label=>"Exit", -underline=>0, -command=>sub{ex +it}); # About $main_menu->command(-label=>"About", -command=>sub{$mainwindow->messageBox(-title=> "About", -message=>"Version 3.0.0", -type => "ok")}); # text variable my $label_firstname; my $entry_firstname; my $label_lastname; my $entry_lastname; my $label_loginid; my $entry_loginid; my $button_add; # -anchor => 'e' | 'w' | 'n' | 's' | 'ne' | 'nw' | 'se' | 'sw' | 'cen +ter' # top ################################ # nw n ne # # # # w center e # # # # sw s se # ################################ # bottom my $f1 = $mainwindow->Frame->pack; # Frame that will hold the grid $label_firstname = $f1->Label(-text => 'Firstname:', )->grid(-row => 0, -column => 0, -sticky => 'e'); $entry_firstname = $f1->Entry(-width => 35,-text => 'Firstname', )->grid(-row => 0, -column => 1); $label_lastname = $f1->Label(-text => 'Lastname:', )->grid(-row => 1, -column => 0, -sticky => 'e'); $entry_lastname = $f1->Entry(-width => 35,-text => 'Lastname', )->grid(-row => 1, -column => 1); $label_loginid = $f1->Label(-text => 'Login ID:', )->grid(-row => 2, -column => 0, -sticky => 'e'); $entry_loginid = $f1->Entry(-width => 35,-text => 'loginID', )->grid(-row => 2, -column => 1); $button_add = $mainwindow->Button(-text => 'Add New User', -command=>sub{exit})->pack(-anchor => 'se'); MainLoop();
In reply to Re: how to align the label and entry text box in my tk GUI
by tybalt89
in thread how to align the label and entry text box in my tk GUI
by fsmendoza
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |