Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

I have a Tk app (ActiveState Perl/Win32) in which I am trying to add some visual effects (control panel lights dimming, etc.) when the user exits the program via the X-button window decoration. I've bound a shutdown routine to the main window destroy event, and it almost works. I can change normal canvas items gradually to get the effect I want. But one item is proving recalcitrant: a Label placed in the canvas with createWindow that acts as a status display. I want it to "go to black" ahead of the entire window disappearing. I've tried deleting it, moving it off the visible portion of the canvas, changing its -foreground to match its -background, undefing its -textvariable or setting it to '', and changing its -state to 'hidden' -- all with an appropriate ->update. But the damn thing just won't go away before the entire window is destroyed!

So I'm wondering if, once the user clicks the little X, it's too late to intercept the destroy event before any actual destruction takes place. I've also tried the OnDestroy method in lieu of bind, but that gives me even less control -- well, no control actually -- over shutdown. I don't want to resort to a window with no decorations and a custom exit button, since the user won't be able to minimize it or move it around. Any ideas?

Update: To answer my own question:

$mw->protocol('WM_DELETE_WINDOW' => \&PowerDown);
intercepts the intent to exit before that intent is acted upon. That's what I was looking for. By the time bind or OnDestroy arrive at the scene, too much damage has already been done.