nr0mx has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I am trying to create a process that receives notifications from other servers and displays them on a monitor GUI. Using a Tk GUI from within a perl script seemed the easiest way of bringing this about, so for the first cut I thought I'd try out the mediachange example given in the "Mastering Perl/Tk" O'Reilly book (Chapter 19). ( The server pops up a MessageBox on every message received. ) First, the error message :
D:\messaging>msgsrvr2.pl xxx.xx.com (10.156.6.45) : hi Free to wrong pool 1d1f228 not 222770 at D:/Perl/site/lib/Tk/MainWindo +w.pm line 55, <GEN1> line 1.
The subroutine that deals with the Tk part:
sub client_connect { # Process a client connect - send our client either an "Ok" or # "Cancel" string, depending upon how the media change went. my($ns, $from) = @_; chomp( $_ = <$ns> ); my $mw = MainWindow->new; $mw->withdraw; $mw->bell; $mw->repeat(15 * 1000 => sub {$mw->bell}); my $reply = $mw->messageBox( -icon => 'info', -type => 'OKCancel', -message => "$from\n\n$_", -wraplength => '6i', -title => 'mediachanged', -background => '#ECFFFF', ); print $ns "$reply\n"; close $ns; exit; } # end client_connect
I am running WinXP. I have ActivePerl 5.8 and ActiveTcl 8.4.6.1 installations. Any ideas ? Is there another forum to pose this question ?

Replies are listed 'Best First'.
Re: Perl/Tk problem on Windows
by eserte (Deacon) on Jun 03, 2004 at 10:00 UTC
    Try
    $mw->destroy; CORE::exit();
    instead of just exit. exit() in conjuction with Tk is evil in forked or threaded environemnts.
      Tried this. It still don't work. Am I missing something fundamental ? I tried changing the code to the below version, but to the same end.
      sub client_connect { my ( $ns, $from ) = @_; chomp($_=<$ns>); print "$from : $_\n"; my $mw = MainWindow->new(); my $t= $mw->Scrolled('Text'); $t->pack(-expand => 1, -fill => 'both' ); tie ( *TEXT, 'Tk::Text', $t ); print TEXT "$from\n\n$_\n"; $mw->destroy; close $ns; CORE::exit(); }
        Are you using fork or threads?