How do I intercept the event when the user clicks the "close" button in a toplevel window?

259 Views Asked by At

When the user clicks the system-provided close button in a toplevel window, I need to free resources.

The question: how do I intercept this event, so that I can call some of my own code?

I've looked through the docs, but can't find anything about destroying toplevel windows.

1

There are 1 best solutions below

2
On BEST ANSWER
use warnings;
use strict;
use Tkx;

my $mw = Tkx::widget->new('.');
$mw->g_wm_protocol('WM_DELETE_WINDOW' => \&cleanUp);

Tkx::MainLoop();

sub cleanUp
{
   print "Cleaning things up\n";
   exit;
}