in reply to Perl/Tk and exit(0)
G'day saw55,
Welcome to the Monastery.
I see the reason for your problem has been explained by ++jcb.
Instead of calling exit(0) as you currently do, consider passing a flag that instructs &timedDialog to either destroy the dialogue or exit the application.
Here's a fully functional, albeit extremely barebones, example of what I mean.
#!/usr/bin/env perl use strict; use warnings; use Tk; { my $mw = MainWindow::->new(); $mw->Button( -text => 'Transient message', -command => sub { out_msg(\$mw, 'Message ...', 2_000) }, )->pack(); $mw->Button( -text => 'No backup', -command => sub { out_msg(\$mw, 'Exiting ...', 2_000, 1) }, )->pack(); } sub out_msg { my ($mw_ref, $msg, $delay, $exit) = @_; my $tl = $$mw_ref->Toplevel(); $tl->Label(-textvariable => \$msg)->pack(); my $handle_msg = $exit ? sub { exit } : sub { $tl->destroy }; $tl->after($delay, $handle_msg); } MainLoop;
Note that the flag is only needed for those callbacks where you want to exit: you may only need to make minimal changes if you adopt this technique.
Here's a few other points that aren't directly related to your current problem:
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl/Tk and exit(0)
by saw55 (Novice) on Apr 03, 2020 at 10:59 UTC | |
by kcott (Archbishop) on Apr 03, 2020 at 21:28 UTC |