I am using Tk to write a program and in the program I have the main window and a couple smaller sub mainwindows that get opened upon certain conditions. Like if changes were made to a file and you try to exit without saving it will recognize there have been changes and pop up another window asking if you want to save. Now if I choose yes I want the program to save the file (which it does) and I want the window to close automatically (which it does not). How could I make this sub window close automatically and not have the main window exit also? Here is the code in question:
sub close { chomp(my $data = $t->get("1.0", "end")); open (TEMP, ">compare") || $t->insert("end", "Cannot open \"compare +\"\n"); print TEMP $data; close(TEMP); if ($filename ne "") { my $compare = compare($filename, "compare"); if ($compare == 0) { exit; }elsif ($compare == -1) { $status->insert("end", "There was an error while comparing!\n +"); }else{ my $sw = MainWindow->new(-title=>"Content Has Changed"); my $frame = $sw->Frame->pack(-side => 'top', -fill => 'x'); $frame->Label(-text => "Would you like to save before exiting +?")-> pack(-side => 'left', -anchor => 'w'); $frame->Button(-text => "No", -background => 'navy blue', -fo +reground => 'white', -command => sub {exit;})-> pack(-side => 'right'); $frame->Button(-text => "Yes", -background => 'navy blue', -f +oreground => 'white', -command =>\&save_and_exit)-> pack(-side => 'right'); } }else{ my $sw = MainWindow->new(-title=>"Save File?"); my $frame = $sw->Frame->pack(-side => 'top', -fill => 'x'); $frame->Label(-text => "Would you like to save before exiting?") +-> pack(-side => 'left', -anchor => 'w'); $frame->Button(-text => "No", -background => 'navy blue', -foreg +round => 'white', -command => sub {exit;})-> pack(-side => 'right'); $frame->Button(-text => "Yes", -background => 'navy blue', -fore +ground => 'white', -command =>\&save_and_exit)-> pack(-side => 'right'); } }
Any ideas?

In reply to clsoing sub window upon execution? by Elijah

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.