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

can anybody tell me how to remove the Tk widgets from a window at runtime.say i have a textbox and a button in a window i need to remove it how can i do it.

Replies are listed 'Best First'.
Re: how to hide the Tk widgets
by rinceWind (Monsignor) on Jul 22, 2005 at 10:39 UTC

    It depends what you want to do. Do you want to completely obliterate the textbox object, or just hide it temporarily?

    To obliterate completely, use $widget->destroy. To temporarily hide it, use $widget->packForget if using the pack geometry manager, or $widget->gridRemove for grid. To make it appear again, call the geometry manager again.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

Re: how to hide the Tk widgets
by Tomtom (Scribe) on Jul 22, 2005 at 10:34 UTC

    I don't anything about Tk, but I managed to find this answer :

    - "withdraw" removes toplevel widgets, including the root window (it's documented under "Toplevel Window Methods, Visibility Methods")

    - To remove child widgets, use the geometry manager's "forget" method ("pack_forget", "grid_forget", etc).

    Hope this helps

Re: how to hide the Tk widgets
by zentara (Cardinal) on Jul 22, 2005 at 11:42 UTC
    #!/usr/bin/perl use warnings; use strict; use Tk; my $top = new MainWindow; my $txt = $top->Scrolled("Text")->pack; $top->Button(-text => "packForget", -command => sub{ my @w = $top->packSlaves; foreach (@w) { $_->packForget; } })->pack(); $top->Button(-text => "Exit", -command => sub {exit})->pack; MainLoop; __END__

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