Well, for starters, in Tk land, anything you do before you execute MainLoop is completed (in most cases) before you see anything displayed. I would add a start button to the widget that starts the loop. Then I would get away from sleep and the for..next. I would use a timer (GUIs should *almost* never block) that repeatedly calls the subroutine that handles the counting and printing.
If you do this, then the loop will not be started until the GUI is up. And your display should be updated since $widget->after() does not put the interface (GUI) to sleep.
I have tested the following modifications, and they work on my system...
#!/usr/local/bin/perl
use strict;
use Tk;
my $Mycount = 0;
my $submain = MainWindow->new();
my $buttons = $submain->Frame()->pack(-side => 'top');
my $status = $buttons->Button(-text => 'Click to Clear',
-command => sub {$submain->destroy;}
)->pack(-side=>'left');
my $text1 = $submain->Text ('-width'=>100, 'height'=>20);
$text1->pack(-side => 'left', -fill => 'y');
my $doit = $buttons->Button(-text => 'Do It',
-command => [ \&theLoop => $submain, \$Mycount],
)->pack(-side=>'left');
$text1->insert('end', "start\n");
$text1->pack;
MainLoop();
sub theLoop {
my $widget = shift;
my $Mycount = shift;
my $line = '';
$$Mycount++;
#for(my $loop=0; $loop <= 3; $loop++ ) ## Looping handled by timer
+...
#{
#sleep 1; Incompatible with Tk MainLoop - It pauses the *enti
+re* application
print "$$Mycount\n";
if ( $$Mycount == 1 ) { $line = "$$Mycount case 1\n"; }
elsif ( $$Mycount == 2 ) { $line = "$$Mycount case 2\n"; }
else { $line = "$$Mycount something else\n"; }
$text1->insert('end', "$line");
#$text1->pack;
#}
## Here is where we implement the delay.... and the loop
## We simply check to see if our loop max has been reached, then i
+f not,
## set a future event to call this subroutine again.
## The 500 is the number of milliseconds to wait before calling.
## This is better programming in Tk, since the sleep command stops
+ everything
## which is very bad with a GUI. (think M$ when a low level call h
+appens)
if ($$Mycount < 3)
{
my $delay = $submain->after(500, [\&theLoop => $widget, $Mycou
+nt]);
}
}
|