There are a couple of different ways. 1 way would be to start your Mainloop with a timer that starts after1 millisecond, to start your long startup process.
$mw->after(1, sub {&startup()}); MainLoop;
That will allow the MainLoop and window to get up and running, before you start your long startup process.

Alternatively you can use waitvisibility, which tells the MainLoop to get the window up before proceeding past that point in the code.

So here is an example, using a simple sleep. However, this is where your REAL problem lies, how to get the STDOUT from your startup processes into your textbox. I've shown 2 subs. One is the standard insert with update, but that won't do you any good if some other program is writing to STDOUT. (Unless you use piped opens, IPC::Open3, etc)

But there is a trick for tieing STDOUT to the test widget, which I have shown. Now, you still need to update the text widget, which I have done in the simple loop. But in your real application startup, you will probably need to resort to a timer which updates the text widget on an interval.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = tkinit; my $textbox = &do_Toplevel(); #to wait until a $widget is visible, use waitVisibility: $mw->waitVisibility; #your long startup code, telling it which textbox to display in #&startup($textbox); &startup1($textbox); MainLoop; ################################################################# sub do_Toplevel { my $tl = $mw->Toplevel(); $tl->title( "Early Status" ); my $text = $tl->Scrolled('Text')->pack(); $text->insert('end',"........startup messages.........\n"); $tl->Button( -text => "Close", -command => sub { $tl->withdraw } )->pack; return $text; } ############################################################## sub startup{ my $textbox = shift; foreach my $num (1..10){ $textbox->insert('end',"$num\n"); $textbox->update; sleep 1; } } ################################################################## sub startup1{ my $textbox = shift; $|++; tie *STDOUT, 'Tk::Text', $textbox; #may need this to force repeated updates # $mw->repeat(10,sub{ $textbox->update }); foreach my $num (1..10){ print "$num\n"; # printing to STDOUT $textbox->update; sleep 1; } } __END__

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

In reply to Re: Perl/Tk windows and status by zentara
in thread Perl/Tk windows and status by herby1620

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.