in reply to Tk::Entry selection problem

Final version:
#!/usr/local/bin/perl use Tk; use Tk ':variables'; use strict; use warnings; my @choices = qw/seeing something important reply reduction renowation + reconnaissance/; # Main Window my $mw = new MainWindow; #GUI Building Area my $frm_name = $mw -> Frame(); #Text Area my $textarea = $mw -> Frame(); my $txt = $textarea -> Text(-width=>40, -height=>10); my $srl_y = $textarea -> Scrollbar(-orient=>'v',-command=>[yview => $t +xt]); my $srl_x = $textarea -> Scrollbar(-orient=>'h',-command=>[xview => $t +xt]); $txt -> configure(-yscrollcommand=>['set', $srl_y], -xscrollcommand=>[ +'set',$srl_x]); my $log = $textarea -> Text(-width=>40, -height=>2); #Geometry Management $frm_name -> grid(-row=>1,-column=>1,-columnspan=>2); $txt -> grid(-row=>1,-column=>1); $log -> grid(-row=>6,-column=>1); $srl_y -> grid(-row=>1,-column=>2,-sticky=>"ns"); $srl_x -> grid(-row=>2,-column=>1,-sticky=>"ew"); $textarea -> grid(-row=>5,-column=>1,-columnspan=>2); $txt->bind('<KeyPress>', [\&OnKeyPress, $txt]); $txt->focus; MainLoop; sub OnKeyPress { my $txtBox = $_[0]; my $currentWord = $txtBox->get('insert -1c wordstart', 'insert'); my $wordEnd = $txtBox->get('insert', 'insert -1c wordend'); $log->delete('0.0', 'end'); $log->insert('end', "wordEnd: <$currentWord, $wordEnd>"); # do not want autocompletion in the middle of the word if(length $wordEnd == 0 # want autocomplete only when typing, not on key up, down, enter, +etc. && $Tk::event->K =~/^[\w]$/) { for(@choices) { if(/^($currentWord)(.*)/) { my $theRest = $2; my $len = length $theRest; my $selFrom = $txtBox->index("insert"); $txtBox->insert('insert', $theRest); $txtBox->tag('add', 'sel', "insert - $len chars", "ins +ert"); $log->insert('end', "matched: <$theRest>"); last; } } } return; }

It took a while searching Google and testing variations of SelectFrom(), SelectTo(), tagging, etc. Until I found tag('add', 'sel', "insert - $len chars", "insert") in sources of Tk::SuperText and voila! I still don't know why this code doesn't work without '-1c', but it seems to be a good start for creating crystal ball.