in reply to Perl/Tk: Need Assistance with use of pack()

In order to get the colons to line up verticaly, you will need to create an invisible frame containing JUST the labels, and make all the labels right-justified.

Then create another frame for the entry fields and place it to the right of that frame (all of that in the major frame).

Center the major frame on the screen, and you're done. In general, You should create frames from the top down (hierarchicaly, not positionaly speaking), and when you want something to line up, you should put that on the edge of a frame.

  • Comment on Re: Perl/Tk: Need Assistance with use of pack()

Replies are listed 'Best First'.
Re: Re: Perl/Tk: Need Assistance with use of pack()
by ozboomer (Friar) on Apr 25, 2004 at 12:46 UTC
    Some good clues there... I've created an 'all-encompassing' frame in addition to the 'field' and 'prompt' frames, and have changed the physical order of when the frames are created and that seems to work better - it actually appears more like there's a hierarchy from 'out to in' on the frames and how pack() deals with them.

    I've also used -anchor to position the frames and Entry items within the frames and things seem to make a bit more sense now (to both Perl AND me!).

    The current problem I'm having now is to work-out why text in a Label is always displayed centred when -justify => 'right' is included in a construct like:-

    my $mw = MainWindow->new; my $pmt3 = $mw->Label( -width => 10, # -height => 3, -justify => 'right', # -text => 'Version: more text is it longer enough', -text => 'Version:', -background => 'magenta', )->pack; MainLoop;
    I've tried looking through a couple of FAQs, tried searching on the web, looking in a couple of my books, etc. but it just doesn't seem to want to work! I'll nut about on it for a while before I post a question on it though.

    Many thanks for your suggestions -- they were very helpful :)

    John

      I suggest a healty reading of Tk::pack (fyi, it is not the only geometry manager)
      use Tk; use strict; use warnings; my $mw = MainWindow->new( -bg => 'beige', ); my $l = $mw->Frame( -width => 111, -height => 333, -relief => "raised", -borderwidth => 2, -bg => '#EEE000', )->pack( -fill => 'x', -side => 'left', -anchor => 'n', ); my $r = $mw->Frame( -width => 111, -height => 333, -relief => "raised", -borderwidth => 2, -bg => '#F0F000', )->pack( -fill => 'both', -side => 'left', -anchor => 'n', ); my $r2 = $mw->Frame( -width => 111, -height => 333, -relief => "raised", -borderwidth => 2, -bg => '#F0F000', )->pack( -fill => 'both', -side => 'left', -anchor => 'n', ); for( qw[ Name: Version: Description: Date: ] ){ $l->Label( -text => $_, # -justify => 'right', -anchor => 'e', )->pack( #-anchor => 'e', # if you don't fill -fill => 'x', ); $r->Label( -text => $_, # -justify => 'right', -anchor => 'e', )->pack( -anchor => 'e', # if you don't fill #-fill => 'x', ); $r2->Label( -text => $_, -justify => 'right', # -anchor => 'e', )->pack( #-anchor => 'e', # if you don't fill #-fill => 'x', ); } #$top->Label(-text => "Enter the scroll frame")->pack; MainLoop;

      MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
      I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
      ** The third rule of perl club is a statement of fact: pod is sexy.

        I've read the docs on pack but couldn't get my head around the 'parcels' and 'cavities' that were referred to. I couldn't get grid to work at all (my program would hang) and I haven't yet tried place. As I've said, I'm new to Tk and I'm just trying to understand how the module works.

        Many thanks for your post.

        John