cognizant has asked for the wisdom of the Perl Monks concerning the following question:

I am working on Perl TK. In the main window, i am using frames with many radio buttons. If i select any one of the option, it should call the corresponding frame in the main window and i will do certain task and after completing the task, it should be vanished. In simple, i want the code similar to $mw->withdraw() for frames. Pls provide me the sample code to make the frame to vanish from the main window. I do not want to disable the frame.
  • Comment on How to close frame after executing in Perl TK?

Replies are listed 'Best First'.
Re: How to close frame after executing in Perl TK?
by davidj (Priest) on Feb 11, 2005 at 10:59 UTC
    you can use the destroy method.

    #!/usr/bin/perl use Tk; use strict; my $mw =MainWindow->new(); # Main Window my $frame = $mw->Frame() -> pack(); #New Frame my $lbl = $frame->Label(-text => "some text")->pack(); my $but = $mw -> Button(-text=>"Destroy frame", -command =>\&destroy_f +rame) -> pack(); MainLoop; #This function will destroy the frame when the button is pushed sub destroy_frame { $frame->destroy(); # destroy method called here }
    hope this helps,
    davidj
      It's working fine. Thanks David.

      --c

Re: How to close frame after executing in Perl TK?
by zentara (Cardinal) on Feb 11, 2005 at 13:16 UTC
    If you are building, then destroying and then rebuilding frames, you will get "psuedo-memory-leaks" in your program. You might be better off with $frame->packForget();

    That way you can reuse the $frame, by rebuilding and repacking it. Of course if your app is just a quick utility, a slight memory gain of 20 or 30 k isn't going to matter.


    I'm not really a human, but I play one on earth. flash japh