Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Tk::Entry acting on <enter>

by gri6507 (Deacon)
on May 16, 2005 at 12:22 UTC ( [id://457427]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks,

I would like to have the following elements in my GUI

------------------------------- ------ | Enter text here | | OK | ------------------------------- ------

I was implementing this with a Tk::Button and a Tk::Entry widget packed into a frame. Normally, the user would enter some text, then hit the button to make an event happen.

How can I make the entry to invoke the same event when the <Enter> key is pressed? The only way I saw was to use validation rules for every key, but it does not appear that <Enter> is a key that gets validated. Does anyone have any suggestions?

Replies are listed 'Best First'.
Re: Tk::Entry acting on <enter>
by kelan (Deacon) on May 16, 2005 at 13:01 UTC

    You can add a key-binding to the entry like so:

    $entry->bind( '<Return>', sub { 'whatever code you want here' } );
    Inside of that anonymous sub can be any code you want, including another sub call or a Tk event generation, etc.

      of course. thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://457427]
Approved by friedo
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-18 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found