Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
What I would like to do is be able to run the script, output to Tk and then exit the script, leaving the Tk widget up and running.

The only way to do that would be to fork off the Tk portion, because if you exit the script you would mess up the Tk event loop. Here is a basic example.

#!/usr/bin/perl use warnings; use strict; use Tk; my $data = 'whatever'; # do whatever here to print to STDOUT or xterm # or # to display the Tk if (fork == 0) { my $top = new MainWindow; $top->geometry('200x200+100+100'); $top->Label( -text=> $data )->pack(); $top->Button( -text => 'Exit', -command => sub { exit })->pack; MainLoop; CORE::exit(); } # always do your forks first, before creating Tk in the main script # my $mw = new MainWindow; # MainLoop; # not needed in this example # non Tk script t can continue here for (1.. 3){ print "$_\n"; sleep 1; } exit; #If you need start a new process from one of the child processes, then #you have to establish some kind of IPC (e.g. pipes) between the child #and parent. #I the launched task running another Perl/Tk module or function or a #complete new program? In the latter case, you should just use fork an +d #exit/system and do not forget to use CORE::exit instead of exit in th +e #child process (according to the FAQ). Perl/Tk forks are somewhat more #difficult. You have to make sure that you fork off the process which #does not have a created a MainWindow itself. This will work fine:

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: backgrounding a Tk process by zentara
in thread backgrounding a Tk process by mpersico

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (11)
    As of 2017-11-23 22:59 GMT
    Find Nodes?
      Voting Booth?
      In order to be able to say "I know Perl", you must have:

      Results (343 votes). Check out past polls.