Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Tk Misalignment

by Lhamo_rin (Friar)
on Jul 03, 2003 at 01:36 UTC ( [id://271036]=perlquestion: print w/replies, xml ) Need Help??

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

When I run the below code, which is part of a bigger program, I am unable to get the From: and the \$from label to align. No amount of changing -height seems to help the situation. Any advice would be appreciated.
my $mw = MainWindow-> new(); $mw->Label(text => "To:", -justify => 'left')-> grid(-column => 1, -ro +w => 1, -sticky => 'w'); $mw->Label(text => "From:", -justify => 'left')-> grid(-column => 1, - +row => 3, -sticky => 'w'); $mw->Entry(-textvariable => \$ARGV[0])-> grid(-column => 2, -row => 1, + -sticky => 'w'); $mw->Label(-textvariable => \$from, -justify => 'left')-> grid(-column + => 2, -row => 3, -sticky => 'w'); $mw->Label(text => "Message:", -justify => 'left')-> grid(-column => 1 +, -row => 5); $mw->Entry(-textvariable => \$msg, -width => 50)-> grid(-column => 2, +-row => 5); $mw->Button(-text => "Send", -command => \&sent)-> grid(-column => 1, +-row => 7); $mw->Button(-text => "Cancel", -command => sub { exit})-> grid(-column + => 3, -row => 7); $mw->title("Support Email"); MainLoop;
Lhamo_rin

Replies are listed 'Best First'.
Re: Tk Misalignment
by Tanalis (Curate) on Jul 03, 2003 at 07:38 UTC
    Morning ...

    I can't replicate your problem on my system (Perl 5.004.04 on Sun Solaris, running Tk 400.202) - it seems to align OK for me.

    Something I did notice is that you're using only alternate rows in the grid when you're laying out the widgets. With my version of Tk, this has the same effect as using consecutive rows: grid doesn't leave any extra space for the empty rows.

    It's possible that it's this that's causing the bad alignment in your version of Perl/Tk, and it might be worth trying using consecutive rows, and then adding additional spacing using the ipad and pad options to increase the size of the cells, if that's what you needed/were trying to do.

    Alternatively, it's maybe worth looking at pack or one of the other layout managers, and seeing if they can do what you need any more reliably.

    Hope that helps.

    -- Foxcub
    #include www.liquidfusion.org.uk

      A minor note about reporting behaviour of Tk apps - you need to report about the window manager too. This was the point of my post.
Re: Tk Misalignment
by zby (Vicar) on Jul 03, 2003 at 07:29 UTC
    Once I had a problem with the pack placement method. It comes out Tk behaves differently under different window managers. Perhaps this thread will shed some light: Packing Frames in callback. Bug?.
Re: Tk Misalignment
by Popcorn Dave (Abbot) on Jul 03, 2003 at 02:30 UTC
    Have you thought about using TK's place geometry? That will give you the ability to place things at specified coordinates so you can line things up.

    If you decide to go that route, I'd suggest laying your app out in something like Paintshop Pro or Photoshop so you get your placement right.

    HTH

    There is no emoticon for what I'm feeling now.

Re: Tk Misalignment
by zentara (Archbishop) on Jul 03, 2003 at 15:49 UTC
    Your example seems to have an error in making the \$from entry a Label instead of an Entry widget. I also rearranged them into a "proper order of appearance". The following code changes now works for me with fvwm2.
    #!/usr/bin/perl use Tk; my $mw = MainWindow-> new(); $mw->Label(text => "To:", -justify => 'left')-> grid(-column => 1, -ro +w => 1, -sticky => 'w'); $mw->Entry(-textvariable => \$ARGV[0])-> grid(-column => 2, -row => 1, + -sticky => 'w'); $mw->Label(text => "From:", -justify => 'left')-> grid(-column => 1, - +row => 3, -sticky => 'w'); $mw->Entry(-textvariable => \$from, -justify => 'left')-> grid(-column + => 2, -row => 3, -sticky => 'w'); $mw->Label(text => "Message:", -justify => 'left')-> grid(-column => 1 +, -row => 5); $mw->Entry(-textvariable => \$msg, -width => 50)-> grid(-column => 2, +-row => 5); $mw->Button(-text => "Send", -command => \&sent)-> grid(-column => 1, +-row => 7); $mw->Button(-text => "Cancel", -command => sub { exit})-> grid(-column + => 3, -row => 7); $mw->title("Support Email"); MainLoop;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://271036]
Approved by phydeauxarff
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-25 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found