Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: tk positioning of widgets

by gibsonca (Beadle)
on Oct 23, 2012 at 16:15 UTC ( #1000493=note: print w/ replies, xml ) Need Help??


in reply to Re: tk positioning of widgets
in thread tk positioning of widgets

OK, I guess a picture is worth apx 1,000 words: What I can do is the following:

---------------------------------- | 400x500 (write only) text area | ---------------------------------- Label1: drop down (user's input echo'd from Label1) Label2: drop down (user's input echo'd from Label2) Select Directory (Text are with user's input dir echo'd) Label3: drop down (User's input echo'd from Label3) : :

What I can not do is put anything on the same line, so as to save space. What does work is letting everything either sorta left justify or default to centered. And I can live with that, but I was hoping to make it look a bit more concise or 'clean'. Thanks!


Comment on Re^2: tk positioning of widgets
Download Code
Re^3: tk positioning of widgets
by zentara (Archbishop) on Oct 23, 2012 at 18:26 UTC
    A program is worth a million words. :-)

    Here is a simple example. For very complex layouts, you can even have subframes within each horizontal frame. For instance when you want very hard to obtain alignments. Here are 2 examples which show the ropes.

    #!/usr/bin/perl use strict; use Tk; use Tk::Pane; my $mw = MainWindow->new; $mw->geometry( '1000x600' ); my $mwf = $mw->Scrolled( 'Pane', -scrollbars => 'ose', -sticky => 'nwse', )->pack( -expand => 1, -fill => 'both' ); # make some frames to contain items on same line my $f1 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' ); my $f2 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' ); my $f3 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' ); my $f4 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' ); my $f5 = $mwf->Frame()->pack( -expand => 1, -fill => 'both' ); # ---------------------------------- # | 400x500 (write only) text area | # ---------------------------------- # Label1: drop down # (user's input echo'd from Label1) # Label2: drop down # (user's input echo'd from Label2) # Select Directory # (Text are with user's input dir echo'd) # Label3: drop down # (User's input echo'd from Label3) my $text1 = $f1->Text(-bg => 'white')->pack(-side => 'left'); my $label1 = $f2->Label(-bg => 'lightseagreen', -text => 'left') ->pack( -side => 'left'); my $label2 = $f2->Label(-bg => 'lightyellow', -text => 'right') ->pack( -side => 'right'); my $text2 = $f3->Text(-bg => 'black')->pack(-side => 'right'); my $label3 = $f4->Label(-bg => 'hotpink', -text => 'bottom') ->pack(); MainLoop();
    and Label alignment
    #!/usr/bin/perl 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 => 'left', -anchor => 'w', )->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;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re^3: tk positioning of widgets
by Anonymous Monk on Oct 24, 2012 at 09:22 UTC

    OK, I guess a picture is worth apx 1,000 words

    :D So first, words which don't paint a picture, and now, a picture of what you're able to accomplish by yourself?

    before (multi line)  perl -MTk  -MTk::WidgetDump  -e " $mw = tkinit; for(0..3){ $f = $mw->Frame(-bg => (qw/ red green blue orange /)[$_] )->pack(qw/-expand 1 -fill both /); $l = $f->Label(-text => qq/T$_/ ); $t = $f->Entry(-text => qq/E$_/); $_->pack(qw/-anchor nw /) for $l, $t; } $mw->WidgetDump; MainLoop "

    after (same line)  perl -MTk  -MTk::WidgetDump  -e " $mw = tkinit; for(0..3){ $f = $mw->Frame(-bg => (qw/ red green blue orange /)[$_] )->pack(qw/-expand 1 -fill both /); $l = $f->Label(-text => qq/T$_/ ); $t = $f->Entry(-text => qq/E$_/); $_->pack(qw/-anchor nw -side left /) for $l, $t; } $mw->WidgetDump; MainLoop "

    after (same line, one stretchy )  perl -MTk  -MTk::WidgetDump  -e " $mw = tkinit; for(0..3){ $f = $mw->Frame(-bg => (qw/ red green blue orange /)[$_] )->pack(qw/-expand 1 -fill both /); $l = $f->Label(-text => qq/T$_/ ); $t = $f->Entry(-text => qq/E$_/); $l->pack(qw/-anchor nw -side left /); $t->pack(qw/-anchor nw -side left -fill x -expand 1 /); } $mw->WidgetDump; MainLoop "

    grid alternative (grid is tricky ) perl -MTk  -MTk::WidgetDump  -e " $mw = tkinit; $f = $mw->Frame(qw/-bg red/)->pack(qw/-expand 1 -fill both /); for(0..3){ $l = $f->Label(-text => qq/T$_/ ); $t = $f->Entry(-text => qq/E$_/); $l->grid(-row => $_, qw/ -column 1 /); $t->grid(-row => $_, qw/ -column 2 -sticky news /);  } $f->Label()->grid(qw/ -row 4 -column 2 -sticky news /);  $f->gridColumnconfigure ( 2, -weight=>1); $f->gridRowconfigure ( 4, -weight=>1); $mw->WidgetDump; MainLoop "

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-09-18 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls