With all of these suggestions, I came up with the following hack (ugly, but it works). Just for the sake of reference, this works for me.
use Tk; use strict; require Tk::ProgressBar; require Tk::Button; $|++; my ( $mw, $progressBar, $cancelCalButton, $runCalButton, $cancel, ); my @data = (0 .. 100); my $dataIndex; my $guiPid = $$; my $childPid; pipe(FROM_PARENT, TO_CHILD) or die "pipe: $!\n"; pipe(FROM_CHILD, TO_PARENT) or die "pipe: $!\n"; select((select(TO_CHILD), $| = 1)[0]); select((select(TO_PARENT), $| = 1)[0]); if ($childPid = fork()){ close FROM_PARENT; close TO_PARENT; } else { die "cannot fork :$!\n" unless defined $childPid; close FROM_CHILD; close TO_CHILD; while(my $line = <FROM_PARENT>){ chomp($line); print "Chid got from parent $line\n"; sleep(10); if ($line == 100){ kill('USR1',$guiPid); #tell the GUI child is done with work next; } kill('USR2',$guiPid); #tell the GUI child has update info print "sending stuff to parent\n"; print TO_PARENT "$line\n"; } print "Done with child\n"; exit(); } $mw = MainWindow->new(); $cancelCalButton = $mw->Button(-text=>"cancel", -command=>\&cancel)->p +ack(); $runCalButton = $mw->Button(-text=>"run",-command=>\&doit)->pack(); $progressBar = $mw->ProgressBar()->pack(); $mw->repeat(100,sub{$mw->idletasks}); $SIG{USR1} = sub { $cancel = 1; $progressBar->value(0); $cancelCalButton->configure(-state=>"disabled"); $mw->idletasks; }; $SIG{USR2} = sub { $runCalButton->configure(-state=>"normal"); print "Got USR2 request\n"; my $value = <FROM_CHILD>; print "parent got $value from child\n"; return if ($cancel); $progressBar->value($value); $runCalButton->configure(-state=>"disabled"); print TO_CHILD "$data[$dataIndex++]\n"; }; MainLoop; sub doit { $runCalButton->configure(-state=>"disabled"); $cancelCalButton->configure(-state=>"normal"); $mw->update; $cancel = 0; $dataIndex = 0; print TO_CHILD "$data[$dataIndex++]\n"; } sub cancel { print "@@@@@@@@@ Got Cancel button @@@@@@@@@\n"; kill('USR1',$$); }

In reply to Re: Tk::Progressbar gives X Error by gri6507
in thread Tk::Progressbar gives X Error by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.