Audar has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I am working on a gui application and currently have it up and running, except for the packing and resizing on the main window and widgets inside it. I have a Mainwindow and a Left and Right Frame -
use strict; use warnings; use Tk; use Tk::Table; use Tk::Pane; use Tk::DialogBox; use Tk::BrowseEntry; use Tk::ProgressBar; require Tk::LabFrame; ##Global Variables my $ffdir = ""; my $outfdir = ""; my $mmthd; my $delim=''; my $cols_maskmthd_tbl; my $mw; #my $xpm; my $cols_tbmasked_lbox; my $mask_but; my $txt; my $be; # Main Window $mw = new MainWindow; $mw->configure(-title=> "SomeTitle"); $mw->minsize(1020,590); $mw->resizable(1,1); #GUI Building Area ## Build left side frame my @leftfrm_options = ( '-relief','ridge','-borderwidth',1); # Main outer left frame my $pane_left_scr = $mw->Scrolled('Pane')->pack( -side => 'left',- +fill => 'both', -expand => 1); #my $frm_left = $pane_left_scr ->Frame(@leftfrm_options)->pack( -s +ide => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec1 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec1_left = $frm_left_sec1 ->Frame(@leftfrm_options)- +>pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' + ); my $frm_left_sec1_right = $frm_left_sec1 ->Frame(@leftfrm_options) +->pack( -side => 'right',-fill => 'both', -expand => 1, -anchor => 'n +w' ); my $frm_left_sec2 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec2_left = $frm_left_sec2 ->Frame(@leftfrm_options)- +>pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' + ); my $frm_left_sec2_right = $frm_left_sec2 ->Frame(@leftfrm_options) +->pack( -side => 'right',-fill => 'both', -expand => 1, -anchor => 'n +w' ); my $frm_left_sec3 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec3_left = $frm_left_sec3 ->Frame(@leftfrm_options)- +>pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' + ); my $frm_left_sec3_right = $frm_left_sec3 ->Frame(@leftfrm_options) +->pack( -side => 'right',-fill => 'both', -expand => 1, -anchor => 'n +w' ); my $frm_left_sec4 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec4_left = $frm_left_sec4 ->Frame(@leftfrm_options)- +>pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' + ); my $frm_left_sec4_right = $frm_left_sec4 ->Frame(@leftfrm_options) +->pack( -side => 'right',-fill => 'both', -expand => 1, -anchor => 'n +w' ); my $frm_left_sec5 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec6 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'center' ) +; my $frm_left_sec7 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec7_left = $frm_left_sec7 ->Frame(@leftfrm_options)- +>pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' + ); my $frm_left_sec7_center = $frm_left_sec7 ->Frame(@leftfrm_options +)->pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'n +w' ); my $frm_left_sec7_right = $frm_left_sec7 ->Frame(@leftfrm_options) +->pack( -side => 'right',-fill => 'both', -expand => 1, -anchor => 'n +w' ); my $frm_left_sec8 = $pane_left_scr ->Frame(@leftfrm_options)->pack +( -side => 'top',-fill => 'both', -expand => 1, -anchor => 'nw' ); my $frm_left_sec8_left = $frm_left_sec8 ->Frame(@leftfrm_options)- +>pack( -side => 'left',-fill => 'both', -expand => 1, -anchor => 'nw' + ); my $frm_left_sec8_right = $frm_left_sec8 ->Frame(@leftfrm_options) +->pack( -side => 'right',-fill => 'both', -expand => 1, -anchor => 'n +w' ); ###Choose delimiter my $choose_delim_lab = $frm_left_sec1_left -> Label(-text=>"Enter +or choose a delimiter:",-width => 22,-anchor => 'nw') ->pack( -side => 'left',-anchor => 'nw',-fill => 'none'); # If user selects item from list manually, invoke do_search $be = $frm_left_sec1_left->BrowseEntry( -variable => \$delim, -browsecmd => \&set_delim ) ->pack( -side => 'right', -expand => 1, -anchor => 'nw',-fill => ' +none' ); #Choose ff my $choose_ff_but = $frm_left_sec2_left -> Button(-text=>" Choose + Files Folder ", -bg => 'yellow' ) ->pack( -side => 'top',-expand => 1, -anchor => 'nw' ); my $choose_ff_lab = $frm_left_sec2_right-> Label(-textvariable=>\$ +ffdir, -bg => 'yellow') ->pack( -side => 'top',-fill=>'x', -expand => 1, -anchor => 'nw' +); ##Choose out folder my $choose_outf_but = $frm_left_sec3_left -> Button(-text=>"Choose + Output Folder", -bg => 'yellow', -command => sub { choose_outf_dir(\ +$outfdir) }) ->pack( -side => 'top',-expand => 1, -anchor => 'nw' ); my $choose_outf_lab = $frm_left_sec3_right -> Label(-textvariable= +>\$outfdir, -bg => 'yellow +') ->pack( -side => 'top',-fill=>'x',-expand => 1, -anchor => 'nw' ); ##Cols to be masked my $choose_cm_labfra = $frm_left_sec4_left->LabFrame( -borderwidth => '2', -label => "Columns To +Mask", -labelside => "acrosst +op", -relief => 'groove') ->pack( -side => 'top',-fill => 'x',-expand => 1, -anchor => 'nw' +); $cols_tbmasked_lbox = $choose_cm_labfra->Scrolled("Listbox", -scro +llbars => "se", -selectmode => "mu +ltiple", -width => 30, -hei +ght=> 10) ->pack( -side => 'top',-fill => 'x',-expand => 1, -anchor => 'nw' +); my $up_down_lab = $frm_left_sec5-> Label(-text=>" ".chr(8593).chr( +8595)." ", -font => 'big') ->pack( -side => 'top',-expand => 0, -anchor => 'center' ); #Choose Masking method my $mask_method_labfra = $frm_left_sec4_right->LabFrame( -borderwidth => '2', -label => "Choose Mask +ing Method", -labelside => "acrosst +op", -relief => 'groove') ->pack( -side => 'top',-fill => 'x',-expand => 1, -anchor => 'nw' + ); my $hash_rdb = $mask_method_labfra -> Radiobutton(-text=>"Hash + ", -value=>"hashed", + -variable=>\$mmthd, -command=>sub {col +s_maskmthd_pairs($mmthd)}) ->pack( -side => 'top',-expand => 1, -anchor => 'w', -pady => 15 ) +; my $scramble_rdb = $mask_method_labfra -> Radiobutton(-text=>"Scra +mble ", -value=>"scram +bled", -variable=>\$mmthd, -command=>sub +{cols_maskmthd_pairs($mmthd)}) ->pack( -side => 'top',-expand => 1, -anchor => 'w', -pady => 20 ) +; my $static_rdb = $mask_method_labfra -> Radiobutton(-text=>"Static + Value ", -value=>"static", + -variable=>\$mmthd, -command=>sub {col +s_maskmthd_pairs($mmthd)}) ->pack( -side => 'top',-expand => 1, -anchor => 'w', -pady => 14 ) +; # allocate a table to the frame $cols_maskmthd_tbl = $frm_left_sec6->Table( -columns => 2, -rows => 7, -fixedrows => 1, -scrollbars => 'e', -relief => 'raised') ->pack( -side => 'top',-fill => 'x',-expand => 1, -anchor => 'cent +er' ); ## Clear ALL my $clrall_but = $frm_left_sec7_left -> Button(-text=>" Clear All + ",-activeforeground => 'red', -command => sub {clear_all()}) ->pack( -side => 'top',-expand => 1, -anchor => 'center' ); ##Execute mask $mask_but = $frm_left_sec7_center-> Button(-text=>" Mask! ", -co +mmand => sub {init_mask()}) ->pack( -side => 'top',-expand => 1, -anchor => 'center' ); #Exit my $exit_but = $frm_left_sec7_right -> Button(-text=>" Exit ",-a +ctiveforeground => 'red', -command => sub {exit_final()}) ->pack( -side => 'top',-expand => 1, -anchor => 'center' ); #Text Area my $pane_right_scr = $mw->Scrolled('Pane' )->pack( -side => 'right +',-fill => 'both', -expand => 1); $txt = $pane_right_scr ->Text()->pack( -side => 'top',-fill => 'bo +th', -expand => 1 ); MainLoop; sub exit_final { exit 0; }
Thank you for the helpful tips kcott, I have now modified my question to be a working example. I also used Tk::Pane as you suggested. The same issue still exists (maybe cause of -fill => 'both', -expand => 1 , as you suggest), but I dont know how else to have the left and right panes, fill the entire left and right halvres respectively and ALSO expand when the application window is expanded. What am I doing wrong? This is what I'm looking for -

---------------------------------------------------------------
|Choose delimiter:           |                                |
|                            |                                |
|Choose Filese Folder        |                                |
|------------- ------------- |                                |
||           ||            | |                                |
||           ||            | |             Text Area          |
||           ||            | |                                |
||           ||            | |                                |
|------------- ------------- |                                |
|                   	     |                                |
|                   	     |                                |
| Clear       Mask      Exit |                                |
---------------------------------------------------------------
Thank you all!
UPDATE :
I was able to fix the issue with - -sticky => 'nsew'
my $pane_left_scr = $mw->Scrolled('Pane',-sticky => 'nsew')->pack( -s +ide => 'left',-fill => 'both', -expand => 1);

Replies are listed 'Best First'.
Re: Perl Tk - Frame packing issue
by kcott (Archbishop) on Feb 02, 2014 at 03:51 UTC

    G'day Audar,

    Welcome to the monastery.

    When asking questions about Tk, please provide a short working example script that we can run. This allows us to reproduce your problem rather than guessing what all the missing code might be. Furthermore, excluding non-essential elements (such as relief, borderwidth, colours, etc.) removes a lot of noise in the code and helps us get to the heart of the problem. Also, a simple piece of ASCII-art, demonstrating the layout you're trying to achieve, is vastly superior to a textual description of what you want: "a picture paints a thousand words".

    I added code to what you posted to get the GUI running. I couldn't reproduce what you described. This is the problem I already mentioned: "guessing what all the missing code might be". I can supply a few suggestions as to where you might be going wrong.

    Using '-fill => 'both', -expand => 1' will tend to force elements to the centre: this may be one of your issues. See Tk::pack paying particular attention to the sections: "DESCRIPTION", "THE PACKER ALGORITHM" and 'EXPANSION". Hint: it's often useful to temporarily set different background colours (-bg option) for every widget to see exactly what space they are taking up.

    The '-anchor' option is a standard widget option as well as a pack() option. I suspect you want the former: check Tk::options and Tk::pack.

    Tk::Frame is not intended to be an interactive widget. From its DESCRIPTION:

    "A frame is a simple widget. Its primary purpose is to act as a spacer or container for complex window layouts. The only features of a frame are its background color and an optional 3-D border to make the frame appear raised or sunken."

    Tk::Pane is probably what you want for the "Scrolled('Frame' ..." code. From its DESCRIPTION:

    "Tk::Pane provides a scrollable frame widget. Once created it can be treated as a frame, except it is scrollable."

    While unrelated to your current problem (as far as I can tell), you really should avoid Indirect Object Syntax. Its use is strongly discouraged: see perlobj: Invoking Class Methods.

    -- Ken

      Thank you kcott, I have modified my question to be a working example now. This is a pic of what I'm looking for - --------------------------------------------------------------- |Choose delimiter: | | | | | |Choose Filese Folder | | |------------- ------------- | | || || | | | || || | | Text Area | || || | | | || || | | | |------------- ------------- | | | | | | | | | Clear Mask Exit | | ---------------------------------------------------------------

        --------------------------------------------------------------- |Choose delimiter: | | | | | |Choose Filese Folder | | |------------- ------------- | | || || | | | || || | | Text Area | || || | | | || || | | | |------------- ------------- | | | | | | | | | Clear Mask Exit | | ---------------------------------------------------------------

Re: Perl Tk - Frame packing issue (Tk::pack)
by Anonymous Monk on Feb 02, 2014 at 03:33 UTC