Ace128 has asked for the wisdom of the Perl Monks concerning the following question:
Hey Monks,
Before I go to the question, I must say that this place really rocks! So many knowledgable people! Little different "forum" layout, but it works fine.
Question:
Ok, say I made this nice GUI in Tk, where I have created several Tk::Frame's (Tk::LabFrame) to seperate the GUI in different sections. Now, I wanna be able of hiding/showing these frames how I choose (along with the stuff on the frames)! Ideas how to do this? Destroy destroys... I want something like $frame->hide(), and $frame->show(); and natrually, the whole GUI is resized...
Ideas? :)
Thanks,
Ace
Re: Hiding and Showing part of the Tk GUI
by mawe (Hermit) on Jul 19, 2005 at 04:53 UTC
|
use Tk;
my $top = new MainWindow;
my $frame = $top->Frame();
$frame->Label(-text=>"Can you see me?")->pack();
$top->Button(-text=>"Hide",-command=>sub{$frame->packForget()})->pack(
+);
$top->Button(-text=>"Show",-command=>sub{$frame->pack()})->pack();
$frame->pack();
MainLoop();
packForget() removes the widget from the packing order. If you repack it later, it appears at the end of the packing order. You can get the pack configuration with @conf = $frame->packInfo(). The same is possible with grid.
Regards, mawe | [reply] [d/l] |
|
Lovely! Works like a charm! This is why I love Tk so much! :) So damn neat, and easy to do otherwise seemable tricky things.
| [reply] |
Re: Hiding and Showing part of the Tk GUI
by waswas-fng (Curate) on Jul 19, 2005 at 02:20 UTC
|
have you tried changing the container's size to 0 and then repacking?
| [reply] |
|
Wow, now that is smart :) (why didnt I just think of that?) No.. Gotta try that...
Update: Um, doesnt seem to work... $frame->geometry("=0x0+0+0");... damn.. would be neat else...
wrong # args: should be "winfo geometry window" at C:\Perl\site\lib/Tk/Submethod.pm
| [reply] |
|