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.

In reply to Tk: Too late to intercept a destroy event? by Dr. Mu

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.