in reply to Dynamically Filling Text Box from Perl Tk

You probably want to implement some kind of update routine that is called periodically. See perldoc Tk::after for details.

#untested, incomplete, adjust to your particular needs sub install_module { my $updater = $top->repeat(500, \&update); do { install module }; $updater->cancel; } sub update { my $output = get_output_from_wherever(); $scrolled_text->insert('end', $output); $top->update; }

Replies are listed 'Best First'.
Re^2: Dynamically Filling Text Box from Perl Tk
by amdme127 (Novice) on Nov 04, 2011 at 18:57 UTC
    tie *STDOUT, 'Tk::Text', $tx;

    To make sure all the output goes to that scrolled text box. I just need this to do it as the module is running and not when it is done. I am taking a look at Tk::after with the hopes of getting that to work. Any other suggestions or recommendations on the best way to dynamically post print to this scrolled text box will be appreciated

      I don't really understand what you are trying to do, can you show a minimum code example? Otherwise, maybe Tie::Tk::Text may be useful.
      #!/usr/bin/perl use warnings; use strict; use Tk; use Tie::Tk::Text; my $mw = MainWindow->new; my $w = $mw->Text()->pack(); tie my @text, 'Tie::Tk::Text', $w; $w->insert('end', "foo\nbar\nbaz\n"); print $text[1]; # "bar\n" MainLoop;

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

        Here is some of the code:

        #This is the main script #!/usr/bin/perl use strict; use Tk; use Cwd; use warnings; use product_search; use missing_articles; require Tk::DialogBox; require Tk::LabEntry; use Spreadsheet::WriteExcel; $tx = $mainFrame->Scrolled(qw/Text -font normal -width 73 -height 15 -wrap word -scrollbars e/ )->pack; tie *STDOUT, 'Tk::Text', $tx; #click Tk button and it calls a module passing the argument and the us +er input product_search::search($si1, $fullSearch);

        The module runs through a list of products and finds matches, formats them for output, such as stripping product numbers if it has any in the product title, etc. As this process compares products, the print command is sending feedback to the user that should output in the scrolled text box above in the main perl script. At the moment, none of the stuff prints to the scrolled text box until the module has completed, instead of giving the user feedback as it runs the module

        Code for module

        #!/cygdrive/c/Perl/bin/perl package product_search; use strict; use strip_product_numbers; sub search { # Grab parameters that are passed to this module my ($si1, $fullSearch) = @_; # As it finds a product that matches, it processes it (strips +product number from title, etc) then should print it print "$product\n\n"; } 1;

        So instead of printing all the products once the module finishes up, I want to print them as it processes. I am also printing status of the module and completion, so in case there is an error the user can give me a better idea where it is erring out, at this time, if the module fails, nothing is printed at all in the scrolled text box which won't help the user to tell me the problem and help me most closely identify it.

        Thanks for all the help