Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl TK Set Focus on LabEntry

Status
Not open for further replies.

clueo8

Programmer
Jun 13, 2005
47
US
I have a popup dialog box which has a lable entry to get user input. Not only would I like to set the focus on the input entry when it pops up, but also, on the pop up window itself (the window stays deselected until the mouse is clicked on it).

None of the '->focus' codes I found work.

Code:
$usr_prompt = $cnv_script_win -> DialogBox (-title => " Prerequisite Script Found!", -buttons => ['Submit']);
$usr_prompt->add('LabEntry', -textvariable => \$resp, -width => 50,
-label => "Please read the following and enter the correct input:", -labelPack => [-side => 'top'])
->pack();
$usr_prompt->Show();
 
Try using -force with the paren of focus.

EX:

Code:
$usr_prompt->focus(-force);

OR

Code:
$widget = $usr_prompt->add('LabEntry', -textvariable => \$resp, -width => 50,
-label => "Please read the following and enter the correct input:", -labelPack => [-side => 'top'])
->pack();

$widget->focus(-force);


Michael Libeson
 
$usr_prompt->focus(-force); did work with making the window active, but It did not set the focus on the labEntry.
 
Try the second option from my previous post.

Code:
$widget = $usr_prompt->add('LabEntry', -textvariable => \$resp, -width => 50,
-label => "Please read the following and enter the correct input:", -labelPack => [-side => 'top'])
->pack();

$widget->focus(-force);


Michael Libeson
 
I did, that did not work at all. I was confused where to put the "$usr_prompt->Show();"... I tried it before and after the focus with no success.
 
I tested the following and it works only with the show after the focus:
Code:
use Tk;
use Tk::DialogBox;
use Tk::LabEntry;
$cnv_script_win = MainWindow->new;
$resp = '';
$usr_prompt = $cnv_script_win -> DialogBox (-title => " Prerequisite Script Found!", -buttons => ['Submit']);
$widget = $usr_prompt->add('LabEntry', -textvariable => \$resp, -width => 50,-label => "Please read the following and enter the correct input:", -labelPack => [-side => 'top'])->pack();
$widget->focus(-force);

$usr_prompt->Show();


Michael Libeson
 
With the window not in focus, I did not see the LabEntry in focus. I added:

Code:
$usr_prompt->focus(-force);
$widget->focus(-force);
$usr_prompt->Show();

To the end to first get the window in focus, then the LabEntry.

Thanks for all your help!

Tim
 
Since I'm on the same subject... Here is the final code:
Code:
my $usr_prompt = $cnv_script_win -> DialogBox (-title => " Prerequisite Script Found!", -buttons => ['Submit']);
my $widget = $usr_prompt->add('LabEntry', -takefocus => undef, -textvariable => \$resp, -width => 50, -background => 'white',
  -label => "Please read the following and enter the correct input:\n\n$cfg_vars[$z]\n", -labelPack => [-side => 'top'])
->pack();
$usr_prompt->focus(-force);
$widget->focus(-force);
$usr_prompt->Show();

I would like to set the label "please read the following..."
to -font => "{Arial} 8"

I put it after the label, before the label pack and that does not do it.
 
Code:
my $usr_prompt = $cnv_script_win -> DialogBox (-title => " Prerequisite Script Found!", -buttons => ['Submit']);
my $widget = $usr_prompt->add('LabEntry', -takefocus => undef, -textvariable => \$resp, -width => 50, -background => 'white',
  -label => "Please read the following and enter the correct input:\n\n$cfg_vars[$z]\n", -font => "arial 8"
, -labelPack => [-side => 'top'])
->pack();
$usr_prompt->focus(-force);
$widget->focus(-force);
$usr_prompt->Show();


Michael Libeson
 
This works as tested.

Code:
use Tk;
use Tk::DialogBox;
use Tk::LabEntry;
$cnv_script_win = MainWindow->new;
$resp = '';
$usr_prompt = $cnv_script_win -> DialogBox (-title => " Prerequisite Script Found!", -buttons => ['Submit']);
$widget = $usr_prompt->add('LabEntry', -textvariable => \$resp, -width => 50,-label => "Please read the following and enter the correct input:", -font => "arial 8")->pack(-side => 'top');
$widget->focus(-force);

$usr_prompt->Show();


Michael Libeson
 
Your code changes the font of the label entry (what the user types in) but the words in:
Code:
-label => "Please read the following and enter the correct input:",
are not changed...
 
Sorry about that. Did you already try -labelfont instead of just -font?

Michael Libeson
 
-labelfont is no recognized... its ok if we can't do this, its the least of my troubles...
 
Code:
use Tk;
use Tk::DialogBox;
use Tk::LabEntry;
$cnv_script_win = MainWindow->new;
$resp = '';
$usr_prompt = $cnv_script_win -> DialogBox (-title => " Prerequisite Script Found!", -buttons => ['Submit']);
$usr_prompt->Label(-text => "Please read the following and enter the correct input:", -font => "arial 24")->pack;

$widget = $usr_prompt->add('LabEntry', -textvariable => \$resp, -width => 50, -font => "arial 8")->pack(-side => 'top');
$widget->focus(-force);

$usr_prompt->Show();


Michael Libeson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top