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

    Thanks you so much, and thanks to jcb as well. As I am sure you you can tell, I am new to Tk, but this gives me something to work with. I knew there were standard popups available--I use them elsewhere in the program--but I think I couldn't figure out how to close them programatically.

      "Thanks you so much"

      You are very welcome.

      "I knew there were standard popups ... but I think I couldn't figure out how to close them programatically."

      Take a look at the invoke() method of Tk::Button. You could give the option to close manually via a button or, if that option isn't taken, close programmatically after the specified delay.

      — Ken