Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

tk frame packing showing inconsistent behaviour

by ghosh123 (Monk)
on Aug 23, 2013 at 05:32 UTC ( #1050591=perlquestion: print w/replies, xml ) Need Help??

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

Hi
My main Tk window has three frames on it - topframe, hlistframe and bottomframe. I want all these frames to be visible when it opens witha geometry of (480x160). But when my hlistframe has 2 rows of data, all frames are visible. But if the data row is increased to 4, the bottomframe is disappearing and I have to stretch the gui to make the bottomframe visible which I do not want. I want the gui size to be as small as (480x160) always and use the scrollbar on the right side when I have many rows of data

Below is my code, please change the @keys array to see the difference

use strict; use warnings; use Tk; use Tk::HList; use Tk::ItemStyle; use Tk::BrowseEntry; use Tk::Toplevel; use Tk::Menubutton; my $sec = 10; my $data = { user1 => { "irun"=>{ "feature" => "queue", "vendor" => "abcd", "issued" => "100", "inuse" => 26 }, }, user2 => { "irun"=>{ "feature" => "queue", "vendor" => "abcd", "issued" => "510", "inuse" => 27 }, }, user2 => { "irun"=>{ "feature" => "batch", "vendor" => "pqrs", "issued" => "100", "inuse" => 222 }, }, user3 => { "irun"=>{ "feature" => "queue", "vendor" => "mnop", "issued" => "500", "inuse" => 244 }, }, user4 => { "irun"=>{ "feature" => "queue", "vendor" => "uvwx", "issued" => "400", "inuse" => 200 }, }, }; # Making the GUI my $mw = tkinit; # new MainWindow; $mw->title("gui"); $mw->geometry("480x160"); my $topframe = $mw->Frame(-width=>5,-height=>10)->pack(-side=>'top',-a +nchor=>'nw',-expand=>0); $topframe->Label(-text => "USER: user1")->pack(-side => 'left',-anchor + => 'w',-padx => 0); $topframe->Label(-text => "Set time(sec)")->pack(-side => 'left',-anch +or => 'w',-padx => 0); my $frequency = $topframe->Entry(-width=> 5,-textvariable=> \$sec)->pa +ck(-side => 'left',-anchor => 'nw',-padx => 0); $topframe->Label(-text => "Select File")->pack(-side => 'left',-anchor + => 'w',-padx => 0); #Help Menu my $menuButton = $topframe->Menubutton(-text => 'Help')->pack(-side=>' +right'); my $menu = $menuButton->Menu (-tearoff => 0); my $user_manual = $menuButton-> cascade(-label => "Manual", -tearoff = +> 0); my $pref = $menuButton-> cascade(-label => "Preference", -tearoff => 0 +); $topframe->BrowseEntry( -state => 'normal', )->pack(-side=>'right',-anchor =>' +e'); my $hlistframe = $mw->Frame()->pack(-fill => 'both',-expand=>1); my $h +l; my $bottomframe = $mw->Frame()->pack(-fill => 'both', -expand => 0); $bottomframe->Button(-text => "Display File",-command => sub {})->pack +(-side=>'right',-anchor => 'ne',-fill=>'x'); my ($general,$label1,$label2,$label3,$label4,$label5,$label6,$label7); $hl = $hlistframe->Scrolled('HList', -scrollbars => 'ose', -columns =>7 , -header => 1, -height => -1, )->pack(-fill => 'both',-expand =>1 ); $label1 = $hl->Label(-text => "Feature", -anchor => 'w'); $hl->headerCreate(0,-itemtype => 'window',-widget => $label1) ; $label2 = $hl->Label(-text => "Vendor", -anchor => 'w'); $hl->headerCreate(1,-itemtype => 'window',-widget => $label2); $label3 = $hl->Label(-text => "Available", -anchor => 'w'); $hl->headerCreate(2,-itemtype => 'window',-widget => $label3); $label4 = $hl->Label(-text => "co lics.", -anchor => 'w'); $hl->headerCreate(3,-itemtype => 'window',-widget => $label4); $label5 = $hl->Label(-text => "co_lics.%", -anchor => 'w'); $hl->headerCreate(4,-itemtype => 'window',-widget => $label5); $label6 = $hl->Label(-text => "co_lic_user", -anchor => 'w'); $hl->headerCreate(5,-itemtype => 'window',-widget => $label6); $label7 = $hl->Label(-text => "co_user%", -anchor => 'w'); $hl->headerCreate(6,-itemtype => 'window',-widget => $label7); $general = $hl->ItemStyle('text', -selectforeground =>'black', -ancho +r =>'center'); #my @keys = qw (user1 user2 user3 user4); my @keys = qw (user1 user2 ); my $path = 0; foreach my $key (@keys) { for my $tool (sort keys %{$data->{$key}}) { _insertData($path,$tool,$key); $path++; } } sub _insertData { my $path = shift; my $tool = shift; my $usr = shift; $hl->add($path); $hl->itemCreate($path,0,-text=> $data->{$usr}->{$tool}->{feature}, +-style => $general); $hl->itemCreate($path,1,-text=> $data->{$usr}->{$tool}->{vendor}, +-style => $general); $hl->itemCreate($path,2,-text=> $data->{$usr}->{$tool}->{issued}, +-style => $general); $hl->itemCreate($path,3,-text=> $data->{$usr}->{$tool}->{inuse}, - +style => $general); $hl->itemCreate($path,4,-text=> "20%", -style => $general); $hl->itemCreate($path,5,-text=> 'N/A', -style => $general); $hl->itemCreate($path,6,-text=> "30%", -style => $general); } MainLoop;

Replies are listed 'Best First'.
Re: tk frame packing showing inconsistent behaviour
by kcott (Bishop) on Aug 23, 2013 at 09:33 UTC

    G'day ghosh123,

    I recommend that you read the Tk::pack documentation, paying particular attention to the "THE PACKER ALGORITHM" and "EXPANSION" sections.

    You specify that $hlistframe should take up the available vertical space with "-side => 'top', -expand => 1", then seem surprised that it does so: claiming it's "showing inconsistent behaviour".

    After you've used up the available space, you add $bottomframe (curiously, given the variable name, as "-side => 'top'") which, obviously, is out of sight until you enlarge the window. You also use "-fill => 'both'" for this frame which, in the context of the code you've posted, makes no sense.

    -- Ken

      As per the doc , if i use -side => top, then the width of the parcel is the width of the cavity and its height is the requested height of the slave plus the -ipady and -pady options.
      So I set a smaller height for the $hlistframe so that it does not use up the available vertical space and some space is still left for the $bottomframe. Also packed the $bottomframe with -side=>bottom. But it is not working.
      May be I am doing something wrong. Plese help.
      Thanks.

        Try reading the algorithm again, paying close attention to the options in -bold

        packorder is packorder it determines who gets dibs first, and you have $bottomframe last in the packorder

        The solution is to change the packorder

Re: tk frame packing showing inconsistent behaviour (Variable "$hl" will not stay shared at)
by Anonymous Monk on Aug 25, 2013 at 07:43 UTC

    You're missing a  my( $hl, $path, $tool, $usr, $data, $general ) = @_; Instead of

    sub _insertData { my $path = shift; my $tool = shift; my $usr = shift; ... $hl->itemCreate($path,0,-text=> $data->{$usr}->{$tool}->{feature}, +-style => $general);

    You're creating a sub that takes arguments, so pass it all the variables its using

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2022-05-24 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?