Hi perl Monks,
I am trying to write a simple code which selects the names from a list box and creates a top level window for that name.
This toplevel window is having two buttons Save and close.
When i open multiple toplevel windows i am unable to store the context of all the windows. i.e when i click on the close button of last recent window it gets closed but when i click on the close button which is present on the rest of the toplevel windows they will not close.
Please help me getting the context of all the toplevel windows. This is the code that i have written:

#!/usr/local/bin/perl use Tk; use Tk::BrowseEntry; my $mw = new MainWindow; $mw->title("Main Window"); my $frame1 = $mw->Frame()->pack(-side => 'top' ); #List for Browse Entry my @List = ("First window","Second Window","Third Window", "Last Windo +w"); $browseentry = $frame1 ->BrowseEntry( -label => "Select Window:", -listheight=> 4, -variable => \$Win_value, -browsecmd => \&Create_Window) ->pack(-side =>'left', -ipady => 5, -pady=>15) +; $browseentry->insert('end', @List); $frame2 = $mw->Frame()->pack(-side => 'bottom'); my $lbl1 = $frame2->Button(-text => 'Close', -command =>sub {$mw->destroy()}) ->pack(-pady =>10); MainLoop; sub Create_Window { our %Window_Info; our $flg = 0; our $my_Win = @_; our $frm1 = join '', @_[1],"_frm1"; our $frm2 = join '', @_[1],"_frm2"; our $caption = join '', @_[1],"_Details"; while (($key, $val) = each(%Window_Info)) { if($key eq @_[1]){ $flg=1; $val ->deiconify( ); $val ->raise( ); } } if ($flg == 0){ $my_Win = $mw ->Toplevel(); $my_Win ->title("$caption"); $my_Win->minsize(qw(800 500)); $my_Win->focus(); #Storing the values in the Hash table $Window_Info{@_[1]}=$my_Win; $frm2 = $my_Win->Frame()->pack(-side => 'bottom' ); #opens the save file dialog wrt the selected toplevel. $frm2->Button(-text => 'Save', -command =>sub {SaveFile($my_Wi +n)})->pack(-side=>'left'); #closes the selected window $frm2->Button(-text => 'Close', -command =>sub {$my_Win->destr +oy()})->pack(-side=>'left'); } }


In reply to Unable to delete a specified toplevel by kranthi

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.