• Lose the fork(), you don't need it. I don't know about Windows, but Tk doesn't survive a fork() on unix. Basically, you can't share a window hierarchy with a child process.
  • The gui itself won't appear until MainLoop(); is entered, unless you muck with Tk::DoOneEvent or something. (update: see another node in this thread for a better answer here )
  • You never pack() any of the windows.
  • So, you have to resort to some trickery to get the main window posted and your "Connecting to agent" code running. I'm sure there's several ways, but Tk::After is what comes to mind for me.

    This is untested, but may be a good start:

    #!/usr/bin/perl my $top2 = MainWindow->new(); my $waitbox = $top2->WaitBox(-title=>"Connecting to agent $port", -txt1=>"Connecting to Agent $port.\nConnection will be establ +ished when this box closes.\n", -cancelroutine=>sub { print "\nCancelling...\n"; $top2->unShow; die} ); # pack the widgets $waitbox->pack; # encapsulate the wait box posting # and the connect routine in a sub # ( the waitbox is just using a "grab" and "focus", # if you want to roll your own, see Tk::Grab ) sub doyourstuff { # post the waitbox, this doesn't block # the process, it just grabs all the keyboard # and mouse events and discards them for a while $waitbox->Show; # do your connect stuff here for (1..10) { print STDERR "waiting $_\n"; sleep(1); } # get rid of the waitbox and start taking mouse/kb # events again. $waitbox->unShow; } # schedule the doyourstuff subroutine to # run in 0 ms $top2->after(0,\&doyourstuff); MainLoop();
    [download]

    In reply to Re: Perl/Tk and "wait" box by kschwab
    in thread Perl/Tk and "wait" box by Anonymous Monk

    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! —
    • How do I compose an effective node title?
    • How do I post a question effectively?
    • Markup in the Monastery
  • 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.