#Build label and text box
$main->Label(
-text => "Input string below:"
)->pack();
$main->Entry(
-textvariable => \$text456
)->pack();
$main->Button(
-text => "Search",
-command =>
sub {
errchk ($text456)
}
)->pack();
The snippet above setups a label, then a box to accept a text based user input. Then a Search button that calls a sub. The way it is written / shown, the search button works as it should. But the search does not execute if I enter text followed by pressing the enter key.
So, the question is, How do I give the user the option to either
input text, then press the enter/return key to begin the search
or
input text, then press the search button to begin the search ?
The first
When the program starts, I want to have the cursor already placed in the text entry box. Right now I have to click in that box, then enter data.
The second
The user should be able to enter data then hit the return key to execute the search
or
enter data and press the search key to execute the search.
#!C:\Perl64\bin\perl.exe
require Tk;
use Tk;
use strict;
my $text456;
my $main = MainWindow->new();
$main->configure(-title => 'Popeyes Cheap Windows Program',
-background => 'blue');
#build separator
my $lin=$main->Frame(-borderwidth=> 8)->pack(-side=>'top');
my $stat=$lin->Label (-width=>40, -height=>0)->pack();
$stat->configure(-text=>"Popeyes Cheap Window Program");
#Build label and text box
$main->Label(
-text => "Enter sumtin below:"
)->pack();
$main->Entry(
-textvariable => \$text456,-width=>7, -borderwidth=>6, -relief=>'sunken'
)->pack();
#Setup Search button/execute input check and search.
$main->Button(
-text => "Search",
-command =>
sub {
errchk ($text456);
dosearch ($text456);
}#end sub
)->pack();