Discussion:
aligning widgets in perl
(too old to reply)
m***@gmail.com
2014-02-18 09:28:41 UTC
Permalink
hi, can you please help i am trying to align my widgets all to the left but it is not working. there are in a frame.

$labelName =$Frame->Frame->pack( -side => 'top', -pady => 15, -anchor => 'nw' );
$labelName ->Label(
-text => 'Name',
-font => '-*-Verdana-Bold-R-Normal-*-*-90-*-*-*-*-*-*'
)->grid($labelName ->Entry( -textvariable => \$new_imp_legend )->pack( -padx => 15 ));
$labelName2 =$Frame->Frame->pack( -side => 'top', -pady => 15, -anchor => 'nw' );
$labelName2 ->Label(
-text => 'Surname',
-font => '-*-Verdana-Bold-R-Normal-*-*-90-*-*-*-*-*-*'
)->grid($labelName2 ->Entry( -textvariable => \$new_imp_legend )->pack( -padx => 15 ));

$CheckButton= $Frame->Frame->pack( -pady => 10, -anchor => 'nw' );
$CheckButton->Label(
-text => 'Are you happy?',
-font => '-*-Verdana-Bold-R-Normal-*-*-90-*-*-*-*-*-*',
)->grid($CheckButton->Checkbutton(
-variable => \$is_cosmetic,
-onvalue => "Y",
-offvalue => "N",
-state => $nstate )->pack() );

please help.
Horst-W. Radners
2014-02-18 10:33:21 UTC
Permalink
Post by m***@gmail.com
hi, can you please help i am trying to align my widgets all to the left but it is not working. there are in a frame.
[...]
Try it this way and look how nice they *all* are aligned to the left
(but also look at the contructors, how $Frame is used as the parent widget):

#!/usr/bin/env perl
use warnings;
use strict;
use Tk;

my $new_imp_legend = 'imp';
my $is_cosmetic = 'Y';
my $nstate = 'normal';

my $mw = MainWindow->new();
my $Frame =
$mw->Frame()->pack( -side => 'top', -anchor => 'nw', -fill => 'both' );

my $labelName = $Frame->Label(
-text => 'Name',
-font => '-*-Verdana-Bold-R-Normal-*-*-90-*-*-*-*-*-*'
)->pack( -side => 'top', -anchor => 'nw' );
my $entryName = $Frame->Entry( -textvariable => \$new_imp_legend )
->pack( -side => 'top', -anchor => 'nw' );

my $labelName2 = $Frame->Label(
-text => 'Surname',
-font => '-*-Verdana-Bold-R-Normal-*-*-90-*-*-*-*-*-*'
)->pack( -side => 'top', -anchor => 'nw' );
my $entryName2 = $Frame->Entry( -textvariable => \$new_imp_legend )
->pack( -side => 'top', -anchor => 'nw' );

my $labelCB = $Frame->Label(
-text => 'Are you happy?',
-font => '-*-Verdana-Bold-R-Normal-*-*-90-*-*-*-*-*-*',
)->pack( -side => 'top', -anchor => 'nw' );
my $CheckButton = $Frame->Checkbutton(
-variable => \$is_cosmetic,
-onvalue => "Y",
-offvalue => "N",
-state => $nstate
)->pack( -side => 'top', -anchor => 'nw' );

MainLoop;


HTH, Horst
--
<remove S P A M 2x from my email address to get the real one>
Loading...