in reply to Cancel close of mainwindow in Tk on Windows


Hi,

jdporter answered this a couple of days ago.

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 ,

I tried it and it does the trick.

Thanks jdporter.

J.C.

Replies are listed 'Best First'.
Re^2: Cancel close of mainwindow in Tk on Windows
by cadphile (Beadle) on Oct 11, 2007 at 23:55 UTC
    J.C.'s/jdporter's solution is much simpler than mine... I think I'll clean up and simplify my own code a bit...!
    Thanks!!