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.


In reply to Re: Tk::Entry selection problem by grizzley
in thread Tk::Entry selection problem by grizzley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.