Hi monks,

I am writing a GUI in Tk. The basic idea is that "work" is selected via the GUI and, once the Run button is clicked, this "work" is executed line by line. Of course, if the user wants to cancel the execution, then simply need to click on the Cancel button. As work is executed, a progress bar displays how much "work" has already been done. The relevant code sections are (pardon the lack of detail, but I didn't want to bore everyone - oh, and I do use strict in the code)

use Tk; use strict; require Tk::ProgressBar; require Tk::Button; my ( $mw, $progressBar, $cancelCalButton, $runCalButton, ); my $guiPid = $$; $mw = MainWindow->new(); $cancelCalButton = $mw->Button(-text=>"cancel")->pack(); $runCalButton = $mw->Button(-text=>"run",-command=>\&doit)->pack(); $progressBar = $mw->ProgressBar()->pack(); $SIG{USR1} = sub { $progressBar->value(0); $mw->update(); $runCalButton->configure(-state=>"normal"); $cancelCalButton->configure(-state=>"disabled"); }; MainLoop; sub doit { my $calPid; $runCalButton->configure(-state=>"disabled"); $cancelCalButton->configure(-state=>"normal"); $mw->update; print "Failed to fork" if (!defined($calPid = fork())); return if ($calPid); for (1 .. 6) { $progressBar->value($_); $mw->update(); sleep(1) } # send the signal to main GUI to reconfigure the button states kill('USR1',$guiPid); kill('INT',$$); }

The Run/Cancel button operation works. Even the progress bar updating works. But, after 2 or 3 updates of the bar, the GUI hangs, and I get the following error message

X Error of failed request: BadIDChoice (invalid resource ID chosen fo +r this connection) Major opcode of failed request: 53 (X_CreatePixmap) Resource id in failed request: 0x1e00077 Serial number of failed request: 1374 Current serial number in output stream: 1300

I am lost on this. Please help. Thank you.


In reply to 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.