Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am trying to make a script where it is possible to use the enter key same as pressing a command button, but only if the entry widget has focus. So that is what i am trying to determine. Here is my code, i just put this together because i am writing a larger program.
use strict; use warnings; use Tk; my $mw = new MainWindow; my $text = $mw->Scrolled("Text", -scrollbars => 'e')->pack(-side=>'bot +tom',-anchor=>'w'); my $label = $mw->Label(-text=>"hello")->pack(-side=>'left',-anchor=>'n +'); my $entry = $mw->Entry()->pack(-side=>'left',-anchor=>'n'); $mw->bind('<Key-Return>',\&verwijs); $entry->focus; MainLoop; sub verwijs{ my $who = $mw->focusCurrent; print %$who; }
The output = "_TkValue_.entry_XEvent_XEvent=SCALAR(0x1ffc334)". So this means the entry widget had focus, but how do i write this an test for it? I can't find any documentation. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [Tk] use enter key iso command button
by tybalt89 (Monsignor) on Jan 25, 2020 at 15:30 UTC | |
by Anonymous Monk on Jan 25, 2020 at 15:47 UTC | |
by Anonymous Monk on Jan 26, 2020 at 05:47 UTC |