xSmallDeadGuyx has asked for the wisdom of the Perl Monks concerning the following question:

EDIT: I have fixed the problem!

I have a script that compiles an STL benchmark in C/C++ using various tools that the company I work for owns. It takes various input from the user through a GUI built with the Tk library. It works fine, compiles everything and then runs it but I have one problem. When you press the "compile" button, everything freezes in the UI and you have to watch the command prompt. I decided that to make the UI better, I should have a status box at the bottom that tells you what is going on and then tells you to watch the command prompt when the program is running. I started by making a frame underneath the compile button with a text box in, like so:

my $statusFrame = $main -> Frame(-background => 'white') -> pack(-side + => 'top', -fill => 'y'); my $status = $statusFrame -> Text(-background => 'black', -foreground +=> 'white') -> pack(-side => 'top', -pady => 9, -padx => 9);

I then made it so that in the compile subroutine, it inserts text into the textbox as it goes along:

sub compile { my $input = $ent0 -> get(); my $image = $ent1 -> get(); my $ccopts = $ent2 -> get(); my $linkopts = $ent3 -> get(); my $cpu = $ent4 -> get(); if($cpp) { $status -> insert("end","Compiling $input.cpp\n"); exit unless *****("$**opts","$input.cpp","$cpu"); # I blanked +out the tool names to hide the companies identity $ccopts .= " -cpp"; } else { $status -> insert("end","Compiling $input.c\n"); exit unless armcc("$**opts","$input.c","$cpu"); } $status -> insert("end","Compiling timer.c\n"); exit unless *****("$**opts","timer.c","$cpu"); $status -> insert("end","Linking $input.* and timer.*\n"); # Also +blanked out the file extensions typical to our company exit unless *******("$linkopts","$image","$input","timer"); # The +linking tool if($opsys eq "MSWin32") #if running windows { $status -> insert("\nRunning program, please watch the command + prompt\n"); exit unless runWindows("$image","$cpu"); } if($opsys eq "linux") #if running linux { $status -> insert("\nRunning program, please watch the termina +l\n"); exit unless runLinux("$image","$cpu"); } }

For some strange reason, the text box stays blank the whole time. I also tried using:

$status -> configure(-text => 'status here');

To no avail! Please help me magic monks!

Replies are listed 'Best First'.
Re: Perl/tk Text Boxes insert problem
by moritz (Cardinal) on Jul 14, 2010 at 13:22 UTC
    By default, the GUI is updated only at the end of each event handler.

    You can change that by calling a special method on Tk, which forces it to update its GUI widgets immediately. Sadly I forgot the name of the method, but I'm sure you can find it in the documentation, now that you know what to search for. (I think it has something with "update" or "idle" or so in the name).

    Perl 6 - links to (nearly) everything that is Perl 6.

      Thank you for your help. I fixed it by putting this code after each section it updates. I also changed the textbox to a label and used configure(-text => "blah"):

      $main => update;