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

I am trying to bind keystrokes from a text entry from the Tk module. Here is the code that is causing the error.
my $textEntry = $mainWindow -> Entry(-state => 'normal') -> pack( -sid +e => 'bottom', -expand => 'BOOLEAN'); $textEntry -> bind('<Return>' => &get); sub get { my $text = $textEntry -> get(); print "$text\n"; }
Now the Error is
Tk::Error: Can't locate auto/Tk/Entry/1.al in @INC (@INC contains: /et +c/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/l +ib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /us +r/local/lib/site_perl .) at /usr/lib/perl5/Tk.pm line 423 Carp::croak at /usr/share/perl/5.10/Carp.pm line 44 AutoLoader::AUTOLOAD at /usr/local/share/perl/5.10.0/AutoLoader.pm li +ne 47 <Key-Return> (command bound to event)

Replies are listed 'Best First'.
Re: Tk Error
by GrandFather (Saint) on Mar 27, 2010 at 02:57 UTC

    It may be you need:

    $textEntry -> bind('<Return>' => \&get);

    bind wants a reference to a sub so unless get returns a reference to a sub, calling get in the bind is not what you want.


    True laziness is hard work
Re: Tk Error
by kiruthika.bkite (Scribe) on Mar 27, 2010 at 04:17 UTC
    Did you create MainWindow object.
    I have executed your code like the following.
    use strict; use warnings; use Tk; my $mainWindow=MainWindow->new; my $textEntry = $mainWindow->Entry(-state => 'normal') -> pack( -side +=> 'bottom', -expand => 'BOOLEAN'); $textEntry -> bind('<Return>' => &get); sub get { my $text = $textEntry -> get(); print "$text\n"; } MainLoop;
    It worked correctly for me.

      What did you try? I ran your code and got exactly the error OP reported - when I pressed the return key in the text edit field.

      After altering the code as suggested in my reply (posted over an hour before your reply) the code works as the OP requires. You could try it (the modified code) yourself as a check. You need to type something into the text edit control then press return and observe that whatever you typed is printed to the console.


      True laziness is hard work
        I was just missing the \ in front of the sub routine call &get. Thanks guys just a dumb typo on my part.