Some more: with
use Tk;
my $main = MainWindow->new( );
$main->protocol( 'WM_DELETE_WINDOW' => sub { print "XXX\n" } );
MainLoop;
the sub will only execute when the close button (or something
similar) of the window manager is used to close the window but
not when you you call "$main->destroy".
If you want to get a sub invoked whenever the window is closed
whatever way you instead should bind the <Destroy> event like
this:
$main->bind( '<Destroy>' => sub { print "YYY\n" if $_[0] == $main } );
Note the check for the first argument the function gets passed:
the sub gets called for each subwidget in the window as it is
destroyed and the first argument is the object getting destroyed.
Thus if you want things to get run once instead for each sub-
widget then you have to return from the sub immediately unless
the argument is the main window.
BTW, there's also the comp.lang.perl.tk newsgroup which might
be an even better place to go to when you have questions about
Perl Tk.
Regards, Jens