Greetings fellow monks,

This is a Tk problem I've tried to find an answer to for some time, and I'm finally posting it here in case anyone knows what I'm missing (whether it be an actual bug in Tk, or just something that's been overlooked).

When I create a non-scrolled Tk frame and pack a new frame into the top of it (with -expand => 1 and -fill => 'x'), it behaves as I would expect.

When I create a similar Tk frame using the "Scrolled" method, though, the newly packed frame inside it doesn't pack to the top of the frame (it stays in the center), and the -expand and -fill options don't seem to work correctly.

The original program is quite large, but this test program shows the same behavior:

#!/usr/bin/perl -w # Strict use strict; use warnings; # Libraries use Tk; use Tk::Pane; use Tk::NoteBook; # Main Program # # Create the GUI, and the top frame my $mw = new MainWindow(); my $top = make_frame($mw, 'white', 'noscroll', 'top', 1, 'both'); # Notebook and notebook pages my $nb = $top->NoteBook()->pack(-expand => 1, -fill => 'both'); my $pg1 = $nb->add('page1', -label => 'Unscrolled'); my $pg2 = $nb->add('page2', -label => 'Scrolled'); # Create subframes (scrolled vs. non-scrolled) my $f1 = make_frame($pg1, 'green', 'noscroll', 'top', 0, 'both'); my $f2 = make_frame($pg2, 'blue', 'scrolled', 'top', 0, 'both'); # Populate frames with subframe containing a label and a button. # Attempt to pack the subframe into the "top" of the containing widget +. label_button_frame($f1, 'gold'); # Packs as expected label_button_frame($f2, 'red'); # Fails to pack nicely?? # Manage gui MainLoop; # Subroutines sub make_frame { my ($parent, $bgcolor, $scrolled, $side, $expand, $fill) = @_; my $b_scr = ($scrolled eq 'scrolled')? 1: 0; my $frame = $b_scr? $parent->Scrolled('Frame'): $parent->Frame(); $frame->configure(-bg => $bgcolor); $frame->pack(-side => $side, -expand => $expand, -fill => $fill); return $frame; } sub label_button_frame { my ($parent, $bgcolor) = @_; my $mw = $parent->toplevel(); my $fr = make_frame($parent, $bgcolor, 'noscroll', 'top', 1, 'x'); $fr->configure(-relief => 'groove', -borderwidth => 4); $fr->Label(-text => 'My Label', -rel => 'groove')->pack(-side => ' +left'); my $pcmd = sub { $mw->destroy }; $fr->Button(-text => 'Exit', -command => $pcmd)->pack(-side => 'ri +ght'); return $fr; }

Running the program shows a notebook with two tabs, labeled "Unscrolled" and "Scrolled".  The "Unscrolled" page shows a yellow frame, packed to the top of its parent frame, with a label "My label" packed to the left, and the "Exit" button packed to the right.

On the "Scrolled" page, I'd like to understand why the red frame doesn't look similar with respect to its position relative to its parent frame, and failure to -expand and -fill in the X direction.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

In reply to Undesired behavior using the Scrolled method in Tk by liverpole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.