You have a right to be confused, it should work. The frame widget is very primitive, and causes alot of hassles. It expands from the inside out, meaning if nothing is packed, it won't show up. You may need to completely packforget the frame from the top level, then repack it. There is also packPropagate to play with. You may need to tell $top to propagate the packing. It's very tricky, so someone else may find a simple fix for you, which I'm overlooking.

Most people have learned to just use a Tk::Pane..... it works better. Try this. You may have to experiment with nesting the Pane into a Frame so the Label dosn't expand too much.

#!/usr/bin/perl use strict; use Tk; require Tk::Pane; my $frame; my $text; my $pane; # Create yellow toplevel window... my $top=MainWindow->new(); $top->configure(-background=>'yellow'); $top->Label(-text=>'Toplevel is yellow')->pack(-side=>'top'); # Create top level listbox... my $list = $top->Scrolled('Listbox', -selectmode=>'single', )->pack(-fill=>'both', -side=>'left'); #create a Pane $pane=$top->Scrolled('Pane', -scrollbars=>'osoe', -background=>'blue'); $list->bind("<<ListboxSelect>>", sub { $pane->pack(-expand=>1, -fill=>'both'); $frame=$pane->Frame(-height=>1)->pack(-side=>'top',-pady=>0); $frame->Label(-text=>'The pane is blue', -height=>1)->pack(-side=>'top',-pady=>0); }); $top->Button(-text=>'Put text into pane', -command=>sub{ if(!$pane){return}; $text->packForget; $text->pack(-in=>$pane); })->pack; $top->Button(-text=>'Take text out of frame', -command=>sub{ $text->packForget; $text->pack(-in=>$top); })->pack; # Create unpacked text window... $text = $top->Scrolled('Text', -wrap=>'none', -background=>'green'); $text->insert('end', 'Green is the text box'); $list->insert( 'end', 'CreateFrame'); MainLoop;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

In reply to Re: Strange Tk Frame Behavior by zentara
in thread Strange Tk Frame Behavior - SOLVED by cmv

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.