in reply to Strange Tk Frame Behavior - SOLVED

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

Replies are listed 'Best First'.
Re^2: Strange Tk Frame Behavior
by cmv (Chaplain) on Feb 07, 2008 at 18:06 UTC
    ++zentara

    Thank you for sharing: my $pane

    OMG: I can't believe I just did that... Sorry all...

    Seriously though, thanks for almost always coming through on the Tk questions. Having you knocking about the monastery gives me great reassurance.

    -Craig