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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |