in reply to closing window and running sub-routine
I'd guess that you are using Perl/Tk? In that case, I'd use a callback of the form
my($dismiss) = $root->Button ( -text => 'dismiss window', -command => sub{ $message->destroy; command();} ); [download]
-Mark