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

hi ,
i'd like to new 2 widget one is type area , one is show out area , when type area type something , then show out area will output something related things?
how can i do that? is it difficult?

Replies are listed 'Best First'.
Re: how Tk wedgets interact?
by dreadpiratepeter (Priest) on Feb 07, 2002 at 14:21 UTC
    Ok, what I think you are saying is that you want an input widget that you can type in and a msg area to display output, based on what was typed in the input box.
    That's actually very simple:
  • create a mainwindow
  • create an entry widget and a msg widget as children of the window and pack them.
  • bind to the enter key in the entry widget a routine that updates the msg area with the appropriate msg.
    That's it. Here's an example:
    #!/usr/local/bin/perl use Tk; use strict; my $mw = Tk::MainWindow->new(); my $entryv; my $msgv; my $entry = $mw->Entry(-textvariable => \$entryv)->pack(-side => 'top' +,-fill => 'x'); my $msg = $mw->Message(-textvariable => \$msgv)->pack(-side => 'top',- +fill => 'both'); $entry->bind('<Return>',sub {$msgv = uc($entryv)}); Tk::MainLoop();


    -pete
    Entropy is not what is used to be.
      oh , thx a lot!

      if there are 2 mainwindow, is it ok?
        IIRC, you can't have 2 main windows. You can create a main window and a toplevel window though. That should work fine.

        -pete
        Entropy is not what is used to be.
Re: how Tk wedgets interact?
by strat (Canon) on Feb 08, 2002 at 13:25 UTC
    quote (if there are 2 mainwindow, is it ok?)

    To be able to create a second MainWindow, you have to destroy the first one...

    #!perl -w use strict; use Tk; my $mw = MainWindow->new(); my $button = $mw->Button( -text => 'killme', -command => $mw->destroy(), )->pack; MainLoop; print "After first MainLoop\n"; my $mw = MainWindow->new(); my $button = $mw->Button( -text => 'exit', -command => exit, )->pack; MainLoop; print "this won't be printed...\n";
    A MainWindow is a special form of a Toplevel; better try to use one MainWindow and one Toplevel instead... </code>

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[\w]~~g=>chop,print"