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

I am trying to write a program with the "Tk" part of perl. I put a text box in it, and I am using code such as:

use Tk; $win = MainWindow->new; $text = $win->Text(-height => 1, -width =>6)->pack; MainLoop;

I was wondering how to get the input from what the person typed in the text box? PLEASE HELP ME!!!!!!!!!!!!!

Replies are listed 'Best First'.
Re: Tk::text input problem
by Ven'Tatsu (Deacon) on May 14, 2004 at 02:32 UTC
    Take a look at the documents for Tk::Text, Look for the method get.
    If your only interested in one line of input you should probably use Tk::Entry instead, it's quite a bit simpler to use than a full Text widget and has better handling for input validation.
Re: Tk::text input problem
by Scarborough (Hermit) on May 14, 2004 at 15:04 UTC
    You may find the monastary tutorial by hiseldl helpful I used it earlier this week to get a start in Tk.
    Tk Tutorial
Re: Tk::text input problem
by zentara (Cardinal) on May 14, 2004 at 15:15 UTC
    Here is a little example to help you get going with the "Entry" widget. Remember, there are more than one way to do things. You can simply get the text with a "print $entry->get". But this example tries to show you how you can pass the entry widget to a subroutine, in case you have multiple entry widgets.
    #!/usr/bin/perl use warnings; use strict; use Tk; my $main = MainWindow->new(); my $entry = $main->Entry(); $entry->pack; $main->Button( -text => 'Print', -command => sub { do_print($entry) } )->pack; MainLoop; sub do_print { my ($widget) = @_; my $entered = $widget->get(); print "The string \"$entered\" was entered.\n"; }

    I'm not really a human, but I play one on earth. flash japh
Re: Tk::text input problem
by aquarium (Curate) on May 14, 2004 at 07:18 UTC
    you bind a variable to the widget..check help on bind