Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Tk: pack, grid or place?

by milarepa (Beadle)
on Sep 11, 2008 at 15:40 UTC ( [id://710653]=note: print w/replies, xml ) Need Help??


in reply to Tk: pack, grid or place?

I started using pack because in most documentation said it's the simplest geometry manager. Honestly at the beginning I felt like a daunting task, but with practice I managed to produce the results I wanted.
Besides taking care of which side you "stack" your widgets, I found that the most important thing with pack is the order in which you place your widgets. For example, I wanted to put several checkbuttons one after the other horizontally. Then I wanted a button just below these checkbuttons. However, after minutes of trial and error I found that the code for the button should go first than the checkbuttons. Here is a snapshot of the code:

#!/usr/perl/bin/perl use Tk; use warnings; use strict; my ($search, $mw, $entry, $text, $io, $checks); my $id = 0; $mw = MainWindow -> new; $mw -> title("AIM"); $mw -> bind('<Key-Escape>' => sub { exit } ); #**************** text ************************* my $scrollbar = $mw->Scrollbar( ); $scrollbar->pack(-side => 'right', -fill => 'y'); $text = $mw -> Text(-font=>"{Verdana} 10 {bold}", -width => 50, -heigh +t => 25, , -yscrollcommand => ['set' => $scrollbar]) -> pack(-side=>'right'); $scrollbar->configure(-command => ['yview' => $text]); #**************** entry ************************* $entry = $mw -> Entry(-font=>"{Verdana} 10 {bold}", -textvariable => \ +$search) -> pack(-side=>'top'); $entry -> bind('<Key-Return>' => \&search ); $entry -> focus; #**************** button ************************* my $btn_clip = $mw -> Button(-text=>"Copy to Clipboard", -command=>sub {$text->clipboardAppend($text->get( +"1.0", 'end'));}) ->pack(-side=>'bottom', -expand=>'1', -anchor=>'n +w'); #*********** checkbutton ************************* foreach (qw/address telephone keyword all/) { $checks = $mw -> Checkbutton( -text => $_) -> pack(-side=>'lef +t', -anchor=>'n'); } MainLoop;
Hope this helps...!!!!

Replies are listed 'Best First'.
Re^2: Tk: pack, grid or place?
by runrig (Abbot) on Sep 11, 2008 at 16:04 UTC
    For me, I found it easier to get the layout I want by packing groups of things into separate frames, e.g., for the checkboxes, I'd just pack a frame to the top, then pack each checkbox to the left in the frame.
      Yes, you are right.
      Another way is to group related widgets into frames. That's exactly what I did with LaTeX Wizard 708332. Honestly when I finish it I felt I was depending too much on frames, so on the next project I wanted to rely more on my ability to use the pack geometry manager. Just for practice and fun.... ;-) !!!!
      That's how we learn new things.
      But Thanks anyway for your comments.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://710653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found