Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Tk::pack help

by Elderian (Sexton)
on Aug 05, 2004 at 06:00 UTC ( [id://380195]=note: print w/replies, xml ) Need Help??


in reply to Tk::pack help

Heya,

i played around a little bit with pack, but it seems to be impossible with a single pack. I could imagine to ways of solving it:

1. As some monks already mentioned, grid would be the geometry manager, which is most suitable for this task.

2. Untested: If it is possible to insert a frame into a frame, you could try the following code:
my $topframe = $mainWindow->Frame; $topframe->pack(-expand => 'x', -fill => 1); my $leftframe = $topframe->Frame; $leftframe->pack(-side => 'left', -expand => 'x', -fill =>1); my $rightframe = $topframe->Frame; $rightframe->pack(-side => 'left', -expand => 'x', -fill =>1);
... but using grid is much easier to and to understand.

Elderian

Replies are listed 'Best First'.
Re^2: Tk::pack help
by eserte (Deacon) on Aug 06, 2004 at 19:28 UTC
    With this approach vertical alignment of the widgets in the frames could be difficult. Here's a hack to use pack() with helper frames to form a gridded structure.
    #!/usr/bin/perl use strict; use List::Util qw(max); use POSIX qw(ceil); use Tk; my $mw = new MainWindow(); my @fields = ("Name", "Street", "Postal code", "City"); my @l; for (@fields) { my $f = $mw->Frame->pack(-fill => "x"); my $l = $f->Label(-text => $_, -anchor => "w")->pack(-side => "lef +t"); push @l, $l; my $e = $f->Entry->pack; } my $maxwidth = max map { $_->reqwidth } @l; my $fontwidth0 = $mw->fontMeasure($l[0]->cget("-font"), "0"); my $maxwidth_chars = ceil($maxwidth / $fontwidth0); for (@l) { $_->configure(-width => $maxwidth_chars); } MainLoop;
    The hack is to set the -width option of the labels to get a uniform width for the left column. In the sample script above this is done dynamically by extracting the width of the largest label. Unfortunately specification of widths is done in characters, but the reqwidth() method returns pixels, so an additional conversion is necessary.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found