Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
See the section on grid in Tk Geometry management.

To be honest, although grid() seems easier and more intuitive to a new programmer, pack() is easier to use, especially when you want to easily handle window resizing by the user.

The primary issue is creating four equally sized frames within a main window

If that is the primary issue, look at how easy pack can do it. And remember, frames only get any size by the size of the widgets they contain. No widgets, no size for the frame. Notice in pack, the -expand and -fill options, which tell the pack() geometry manager how to handle resizes. Your can have just x or y filling with -fill=>'x" or -fill=> "y".

I hardly ever resort to using grid(), but I seem to recall it's resizing is a bit more complex to handle.

#!/usr/bin/perl use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry('400x250'); my $mwf = $mw->Scrolled('Pane', -scrollbars=>'osoe', -sticky=>'nwse', )->pack(-expand=>1, -fill=>'both'); my %frame; # hash for holding frames for (1..4){ $frame{$_} = $mwf->Frame()->pack(-expand=>1,-fill=>'both'); } my %canv; for (0..4){ $canv{$_}{'obj'} = $frame{1}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'white', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left' ,-padx=>10,-pady=>10, -expand=>1, -fill=>'bo +th'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (5..9){ $canv{$_}{'obj'} = $frame{2}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'lightseagreen', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'bo +th'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (6..10){ $canv{$_}{'obj'} = $frame{3}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'yellow', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'bo +th'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } for (11..15){ $canv{$_}{'obj'} = $frame{4}->Scrolled('Canvas', -height => 100, -width => 100, -bg =>'hotpink', -scrollbars => 'osoe', -scrollregion => [ 0, 0, 500, 500 ], )->pack(-side =>'left', -padx=>10,-pady=>10 ,-expand=>1, -fill=>'bo +th'); $canv{$_}{'obj'}->createText(50,50, -text => $_, -anchor => 'center', ); } MainLoop();

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: TK Geometry Management by zentara
in thread TK Geometry Management by shortyfw06

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-26 01:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found