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

I'm not asking much. All I want to do is to be able to click a button and destroy a widget at the top level without exiting my entire script. Using the Tk::DialogBox widget comes pretty close to what I want. Unfortunately, it doesn't allow removing a widget once it has been added to the top level frame. Can anyone help me? Thanks, Merrick

Replies are listed 'Best First'.
Re: OO novice with Perl/Tk
by kevin_i_orourke (Friar) on Jun 25, 2001 at 13:08 UTC

    I'm not quite clear what you're trying to do. Is the widget you are trying to destroy the toplevel window itself? If it's the MainWindow for your application then this always exits.

    For non-toplevel widgets you should just be able to use $widget->destroy().

    Kevin O'Rourke

      That did the trick. I'm learning from the O'Reilly Perl Bookshelf series. They never make this clear in the gui building chapters. Thanks! Merrick
      use Tk; choice(); # After the widget vanishes # the program continues here ... print "Success!!\n"; sub choice{ $top = MainWindow -> new(); $frame = $top -> Frame() -> pack(); $button = $frame->Button (-text => 'Kill', -command => sub{$top -> destroy()} )->pack(); MainLoop; }
Re: OO novice with Perl/Tk
by holygrail (Scribe) on Jun 25, 2001 at 16:54 UTC
    Let me get this straight: You want to use Tk::Dialogbox and let the callback remove a widget on the toplevel window?
    That should be possible.

    I suggest you post your code here and explain a bit more...

    --HolyGrail
      I accomplished what I needed using $widget -> destroy(). Thanks for your help, Merrick