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.