in reply to How to catch pushing the window "Exit" button in Perl/Tk?
Trap the window manager exit signal and redirect to your own exit routine. Cross platform. This won't trap someone closing or entering ctrl-c in the command.exe window. The best way to defend against that is to use wperl. (under windows)
Oops. zentara posted the correct answer while I was typing. Anyway; me too!
use warnings; use strict; use Tk; use Tk::DialogBox; my $mw = MainWindow->new; $mw->protocol('WM_DELETE_WINDOW' => \&myexit); MainLoop; sub myexit{ my $db = $mw->DialogBox(-title => "Are you sure you want to exit?" +, -buttons => ['OK', 'Cancel']); my $answer = $db->Show; Tk::exit if $answer eq 'OK'; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to catch pushing the window "Exit" button in Perl/Tk?
by Shumkar (Novice) on Aug 18, 2010 at 18:08 UTC |