in reply to Ending an application gracefully

I think you can register a callback for the WM_DELETE_WINDOW property that shuts down gracefully. I don't have my example code with me, but it should be in the Perl/Tk book. Something like:

$toplevel->protocol( WM_DELETE_WINDOW, \&end_gracefully );