in reply to Handling child process and close window exits in Perl/Tk

second Perl/Tk script to get some input from the user. The second is standalone because it's general purpose and I didn't want to rewrite it every place I want to use it.

Well you sure are "beating your head against the wall" doing it that way. Just spend a few minutes and put the popup code into a module, that you can call from your scripts. That way you can return the user input into local variables. If you need help on how, show us the context you need to get user info, (a small example script), and we can show you a simple popup module.

For example:

#!/usr/bin/perl use Tk; my $MainWindow = MainWindow->new; $MainWindow->title("Data Entry Form"); $MainWindow -> Label(-justify => 'left', -text => "Name of person : ") ->pack(-side => 'left',-anchor => 'n'); my $entry = $MainWindow -> Entry(-selectborderwidth => 10) ->pack(-side => 'top',-anchor => 'n'); $entry->bind('<Return>',[\&somesub]); $entry->focus; $MainWindow -> Button(-text => "OK", -command => \&somesub) ->pack(-side => 'bottom',-anchor => 'center'); MainLoop; #your script can continue here after Tk is done while(1){print time; sleep 1;} sub somesub { $,="\n"; $NameOfPerson = $entry -> get; print "\nNameOfPerson ->$NameOfPerson\n"; $MainWindow -> destroy; }
Is there a way to catch that 'x' signal?

Yes.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; $mw->title("Close test"); $mw->geometry("400x250"); #prevents mw from closing $mw->protocol('WM_DELETE_WINDOW' => sub { print "do stuff here before the exit\n"; exit; }); MainLoop;

I'm not really a human, but I play one on earth. Cogito ergo sum a bum