use strict; use warnings; use Tk; use Tk::DialogBox; # User-defined my $b_destroy_button = 0; # If set, destroy the Button, not the MainWindow # Main program my $mw = MainWindow->new(); my $button = $mw->Button(-text => 'Exit'); # Choose which widget to destroy my $psub; ($b_destroy_button) or $psub = sub { $mw->destroy() }; ($b_destroy_button) and $psub = sub { $button->destroy() }; $button->configure(-command => $psub); $button->pack(-side => 'right', -ipadx => 10, -padx => 30); $button->OnDestroy(\&exit_app); MainLoop; # Subroutines sub exit_app{ print "1\n"; my $db = $mw->DialogBox(-title => 'Error',-buttons => ['CSV','Abandon']); my $text = "Do you wish to save a new CSV file or abandon changes?"; $db->Label(-text => $text)->pack(); my $button = $db->Show(); if ($button eq 'CSV'){ save_csv(); } } sub save_csv{ return 1; } #### use strict; use warnings; use Tk; use Tk::DialogBox; # Main program my $mw = MainWindow->new(); my $button = $mw->Button(-text => 'Exit'); $button->configure(-command => \&exit_app); $button->pack(-side => 'right', -ipadx => 10, -padx => 30); MainLoop; # Subroutines sub exit_app{ print "1\n"; my $db = $mw->DialogBox(-title => 'Error',-buttons => ['CSV','Abandon']); my $text = "Do you wish to save a new CSV file or abandon changes?"; $db->Label(-text => $text)->pack(); my $button = $db->Show(); if ($button eq 'CSV'){ save_csv(); } $mw->destroy(); } sub save_csv{ return 1; }