[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Tkinter - incremental input ?

Helmut Jarausch

1/30/2008 12:32:00 PM

Hi,

I don't want to reinvent the wheel but I cannot find it so far.

Many editors have a so-called incremental search feature.
As you type characters, elements of a set of strings which fit so far are
displayed or at least, the first one of these is displayed.

Now I want to do something similar in Tkinter - an Entry widget
which displays possible 'completions'
e.g. given the list of names (...,'Hardy','Helmut',..)

As soon as enter the character 'H' the string 'Hardy'
would be displayed in the Entry widget - but the cursor
is still at position 2 (given 'H' is a position 1)
Furthermore, as soon as I enter 'e', it would change the
text to 'Helmut', and so on.

While I can bind '<Key>' to a callback, I haven't figured out how
to get (and later on set) the cursor within the Entry widget.
In other words I need to know at which character position the last
character was entered.
Currently I can only see the brute force method: keeping track of
all cursor positioning means like <Backspace>, <Del>, the '<-' and '->' keys
and mouse clicks.
Is there an easier method?

Many thanks for a hint or even a pointer to an example,
Helmut.

--
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
1 Answer

Eric Brunel

1/30/2008 4:08:00 PM

0

On Wed, 30 Jan 2008 13:32:00 +0100, Helmut Jarausch
<jarausch@igpm.rwth-aachen.de> wrote:
[snip]
> While I can bind '<Key>' to a callback, I haven't figured out how
> to get (and later on set) the cursor within the Entry widget.
> In other words I need to know at which character position the last
> character was entered.

You can get the position of the insertion point with
entry.index('insert'), and set it via entry.icursor(index). If you want to
do this as the user types, take care to bind to KeyRelease; this way, the
character corresponding to the key has already been entered in the entry.

BTW, you may also want to automatically select the part that the user
hasn't actually typed. This can be done with entry.selection_clear(), then
entry.selection_range(start_position, end_position).

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"