Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tk - withdraw frame ? 1

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
Hi,

can I hide one frame while unhiding another - actaully switching betwen frames that would appear in the same location ?

when I try "$frame1->withdraw" I get error :
Failed to AUTOLOAD 'Tk::Frame::withdraw' at D:\DOcuments\myscripts\nettest.pl line 200

thanks

Long live king Moshiach !
 
Use pack and packForget. Here's a full working example. I put the two frames that are gonna swap places inside of a wrapper frame, so that they're the only widgets that will appear in those frames (for ease of use... if you packForget something and then pack it again, the order of widgets might become incorrect... you'd find that out through experimentation. There are ways around it).

Code:
#!/usr/bin/perl -w

use Tk;

my $mw = MainWindow->new();
$mw->geometry ('320x240');

# Create a bottom-aligned frame for the button and a "main" frame for the
# rest of the window's contents.
my $bottom = $mw->Frame->pack (-side => 'bottom', -fill => 'x');
my $main   = $mw->Frame->pack (-side => 'bottom', -fill => 'both', -expand => 1);

# For ease, the frames that'll appear and disappear will both be inside of a
# "wrapper" frame, which will contain only ONE of the two frames.
my $wrapper = $main->Frame->pack (-fill => 'both', -expand => 1);

# Create the two frames. Only pack one of them.
my $frame1 = $wrapper->Frame (-background => 'blue')->pack (-fill => 'both', -expand => 1);
my $frame2 = $wrapper->Frame (-background => 'red');

# Put something in them.
my $lab1 = $frame1->Label (
    -text => 'Hello, world!',
    -font => [
        -family => 'Helvetica',
        -size   => 16,
        -weight => 'bold',
    ],
    -background => 'blue',
    -foreground => 'white',
)->pack;
my $lab2 = $frame2->Label (
    -text => 'Hello, mars!',
    -font => [
        -family => 'Times',
        -size   => 16,
        -weight => 'bold',
    ],
    -background => 'red',
    -foreground => 'white',
)->pack;

# And a button to swap the frames.
my $switch = 0;
my $btn = $bottom->Button (
    -text => 'Swap Frames',
    -command => sub {
        if ($switch == 0) {
            $frame1->packForget();
            $frame2->pack (-fill => 'both', -expand => 1);
            $switch = 1;
        }
        else {
            $frame2->packForget();
            $frame1->pack (-fill => 'both', -expand => 1);
            $switch = 0;
        }
    },
)->pack (-pady => 2);

MainLoop;

-------------
Cuvou.com | My personal homepage
Project Fearless | My web blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top