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

I've been working on a little script that pulls information out of 2 different databases based on one search string and then displays certain fields. I had the program working perfect, then wanted to put a TK interface onto it. It works okay with a command line interface, but I want to let the user search from inside the program. The problem is, once the program reaches the end there is MainLoop() which creates all of the TK fields and tables and everything. When the user inputs a search string, I want it to recreate these but I can't figure out how. Is there any way to force TK to recreate all of its fields? Kevin

Replies are listed 'Best First'.
Re: Perl/TK Database
by Eradicatore (Monk) on Jun 06, 2001 at 18:19 UTC
    I assume the user inputs a search string in some tk widget like an entry widget? So what you need to do is just create a subroutine that calls the "configure" widget option for all the labels or other widgets that your created so far.

    for example:

    #!/usr/local/bin/perl use Tk; my $mw = MainWindow->new(); $button = $mw->Button(-text => "hello", -activebackground => 'red', -command => \&printit)->pack(); MainLoop; sub printit { $button->configure(-text => "you pressed me"); }

    Justin Eltoft

Re: Perl/TK Database
by clintp (Curate) on Jun 06, 2001 at 18:16 UTC
    I'm not entirely sure what you're asking. If you want Perl/Tk to redraw a widget (that you've changed somehow behind the scenes), just do this:
    $widget->update();
    If you're processing and want Tk to be responsive (redraws, respond to events, etc...) during that processing, then call idletasks on the top-level widget in your processing loop:
    $mainwindow->idletasks();
Re: Perl/TK Database
by Jouke (Curate) on Jun 06, 2001 at 18:47 UTC
    You should keep in mind that once you draw all widgets on the screen, you have to assign actions to buttons and bind the output to other widgets. If you define a button which should take an action, you should return the result in (for example) a labelwidget, like: (note: I can't test where I am now, so this code is not tested!)
    #!/usr/bin/perl -w use strict; use Tk; my $mainwindow = MainWindow->new(); my $label = $mainwindow->Label(-text => "This is before you press the +button") ->pack(); my $button = $mainwindow->Button( -text => "press to change the lab +el", -command => sub { $label->configure(-text => "This changed t +he label") } )->pack(); MainLoop();
    I hope this clarifies it...

    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory