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

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

Replies are listed 'Best First'.
Re: Re: Re: Perl/Tk: Need Assistance with use of pack()
by PodMaster (Abbot) on Apr 25, 2004 at 12:59 UTC
    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

        You can't mix pack() and grid() in the same frame or toplevel (this would cause your program hanging). Either use grid() all over the place or create a frame where you just use grid().