Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: How to pack 3 frames, one to the right of two on the left.

27 views
Skip to first unread message

Horst-W. Radners

unread,
Mar 21, 2012, 3:10:42 PM3/21/12
to
Mazur wrote on 21.03.2012 18:51:
> I've been trying to arrange 3 frames like this, with pack:
>
> +-------------------+ +----+
> | | | |
> | | | |
> +-------------------+ | |
> +-------------------+ | |
> | | | |
> | | | |
> | | | |
> | | | |
> | | | |
> | | | |
> | | | |
> | | | |
> | | +----+
> | |
> +-------------------+
>
> However, I can't seem to find the right way to use -side and/or -
> anchor to achieve this. This is partly due to not
> fully comprehending the relative strengths and workings of those two
> options, and not finding a web-page dealing such. Is there another
> way than using grid with overlaps?
>
> Mazur

When using pack() for complex layouts, you make heavy use of hierarchical
sub(-sub(-sub))-frames, try this example (-bg, -padx/y and explicit -height,
-width for demo only, of course):


use warnings;
use strict;
use Tk;

my $mw = MainWindow->new();

my $fr1 = $mw->Frame( -bg => 'blue' )
->pack( -side => 'left', -anchor => 'nw' );
my $fr1a = $fr1->Frame( -height => 50, -width => 200, -bg => 'cyan' )
->pack( -padx => 2, -pady => 2, -side => 'top', -anchor => 'nw' );
my $fr1b = $fr1->Frame( -height => 300, -width => 200, -bg => 'magenta' )
->pack( -padx => 2, -pady => 2, -side => 'top', -anchor => 'nw' );
my $fr2 = $mw->Frame( -height => 330, -width => 50, -bg => 'green' )
->pack( -padx => 2, -pady => 2, -side => 'left', -anchor => 'nw' );

MainLoop;


$fr2 could also be pack()'ed with (-side => 'right', -anchor => 'ne'),
the difference shows when resizing the window.

When learning Tk you should definitely read 'Mastering Perl/Tk' by
Steve Lidie and Nancy Walsh, online e. g.
http://docstore.mik.ua/orelly/perl3/tk/index.htm

Horst
--
<remove S P A M 2x from my email address to get the real one>
0 new messages