Hi Monks,
I need some help with a GUI application i have been trying to build lately. One of the major problems i'm facings is when i try to close the Top level widget by destroying it(see code) and try to reload it later, the widget don't auto load and gives me the error

Tk::Error: Failed to AUTOLOAD 'Tk::Widget::insert' at C:/Dwimperl/perl +/site/lib/ Tk/Derived.pm line 469 Carp::croak at C:/Dwimperl/perl/lib/Carp.pm line 100 Tk::Widget::__ANON__ at C:/Dwimperl/perl/site/lib/Tk/Widget.pm line 3 +47 Tk::Derived::Delegate at C:/Dwimperl/perl/site/lib/Tk/Derived.pm line + 469 Tk::Widget::__ANON__ at C:/Dwimperl/perl/site/lib/Tk/Widget.pm line 3 +22 main::push_button2 at top.pl line 62 Tk callback for .toplevel.button1 Tk::__ANON__ at C:/Dwimperl/perl/site/lib/Tk.pm line 251 Tk::Button::butUp at C:/Dwimperl/perl/site/lib/Tk/Button.pm line 175 <ButtonRelease-1> (command bound to event)

Please help..!! Below is the code:
#!/usr/local/bin/perl use Tk; require Tk::ROText; require Tk::TextUndo; use Carp; use Tk::widgets qw(Canvas); use Tk::Xlib; use Math::Cartesian::Product; use List::Util qw[min max]; use List::MoreUtils qw(firstidx); # Main Window my $mw = new MainWindow; $mw->title('File preview'); $mw->scaling($ARGV[0]) if (@ARGV); my $screen = $mw->Screen; my $width1 = $screen->WidthOfScreen; my $height1 = $screen->HeightOfScreen; $mw->Frame(-background => 'red')->pack(-ipadx =>50, -side => "left", - +fill => "y",); #Making a text area my $txt = $mw -> Scrolled('ROText',-width => $width1, height => $heigh +t1, -scrollbars=>'e', -font => "fixed 10 bold") -> pack (); $txt->insert('end', ""); #Declare that there is a menu my $mbar = $mw -> Menu(); $mw -> configure(-menu => $mbar); #The Main Buttons my $file = $mbar -> cascade(-label=>"File ", -underline=>0, -tearof +f => 0); my $tool= $mbar -> cascade(-label =>"Tools ", -underline=>0, -tearo +ff => 0); my $parser = $mbar -> cascade(-label =>"Check ", -underline=>0, -te +aroff => 0); my $help = $mbar -> cascade(-label =>"Help ", -underline=>0, -tearo +ff => 0); ## Tools Menu ## $tool -> command(-label => "ABC", -underline=>0, -command=> \&nwplan ); $tool -> command(-label => "CC", -underline=>0, -command=> \&optimize ); $tool -> separator(); $tool -> command(-label =>"WW", -underline =>1, -command => \&do_top); $tool -> command(-label =>"Clear", -underline => 0, -command => sub {$txt->delete('1.0','end');}); MainLoop; sub do_top { if (! Exists($tl)) { $tl = $mw->Toplevel; $tl->title('Help'); $tl->geometry( "1000x700" ); my $frame = $tl->Frame()->pack; my $lab = $tl->Label()->pack; my $ent = $tl->Entry()->pack; $tl->Button(-text => 'Exit',-command => sub { $tl->destroy;})->pa +ck; $tl->Button(-text => 'Open File1',-command =>\&push_button2)->pack; my $text = $tl->Scrolled('Text')->pack(); sub push_button2{ $text->insert('end',"You pushed button2\n");} } else { $tl->deiconify; $tl->raise; } }

In reply to failed AUTOLOAD widgets when trying to destory widget by reaper9187

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.