I used the words may and easy in "... you may end up with no (easy) way ..." quite deliberately as I have no knowledge of what platform the OP is using. Regardless, we both seem to be in agreement that an "Exit" button is a good idea.

"I prefer one that doesn't call exit"

Why do you have that preference? Do you perhaps think that exit in a Tk callback refers to CORE::exit?

Take a look at this from Tk::exit:

"If calling exit from code invoked via a Tk callback then this Tk version of exit cleans up more reliably than using the perl exit."

and a little further down

"... Tk::exit is imported by default ..."

or simply look in your copy of Tk.pm:

... @EXPORT = qw(Exists Ev exit MainLoop DoOneEvent tkinit); ...

As for destroy() (documented in Tk::Widget), you'd only need to use that (on your MainWindow object) if you had code after MainLoop which you needed to execute. Here's an example of the difference:

#!/usr/bin/env perl use strict; use warnings; use Tk; my $mw = MainWindow->new; $mw->Button(-text => 'Exit', -command => sub { exit })->pack; $mw->Button(-text => 'Destroy', -command => sub { $mw->destroy })->pac +k; MainLoop; print "After MainLoop\n";

Sample runs:

$ pm_tk_exit_vs_destroy.pl # Using 'Exit' button $ pm_tk_exit_vs_destroy.pl # Using 'Destroy' button After MainLoop $

-- Ken


In reply to Re^3: Border-less main window (Alt+F4 Ctrl+C by kcott
in thread Border-less main window by Anonymous Monk

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.