in reply to How to call back when exiting the main window

You can handle the WM_DELETE_WINDOW protocol:

use Tk; use Tk::Dialog; my $mw = new MainWindow; $mw->Button( -text => "Exit", -command => \&confirm_exit )->pack; $mw->protocol( WM_DELETE_WINDOW => \&confirm_exit ); my $exit_dlg = $mw->Dialog( -text => "Really exit?", -buttons => [qw(Y +es No)], -default_button => 'Yes' ); MainLoop; warn "exited MainLoop\n"; sub confirm_exit { my $yn = $exit_dlg->Show; $yn =~ /y/i or return; warn "destroying MainWindow\n"; $mw->destroy; }
A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^2: How to call back when exiting the main window
by dannytrannox (Initiate) on Oct 09, 2007 at 21:47 UTC
    Thanks monk jdporter, it works!
    Much appreciate it.
    Danny.