Tkinter - incremental input ?

Discussion in 'Python' started by Helmut Jarausch, Jan 30, 2008.

  1. 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
     
    Helmut Jarausch, Jan 30, 2008
    #1
    1. Advertising

  2. Helmut Jarausch

    Eric Brunel Guest

    On Wed, 30 Jan 2008 13:32:00 +0100, Helmut Jarausch
    <-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+-'])"
     
    Eric Brunel, Jan 30, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Incremental search

    Mark Goldin, Jul 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    2,946
    rxiong
    Aug 25, 2010
  2. Luis Ferrao

    DataGrid: iTunes-like incremental search

    Luis Ferrao, Jan 10, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    975
    Luis Ferrao
    Jan 10, 2005
  3. Kevin McMurtrie

    Need help with incremental GC failure

    Kevin McMurtrie, Jun 19, 2004, in forum: Java
    Replies:
    0
    Views:
    657
    Kevin McMurtrie
    Jun 19, 2004
  4. Kevin McMurtrie

    Need help with incremental GC failure

    Kevin McMurtrie, Jun 19, 2004, in forum: Java
    Replies:
    0
    Views:
    642
    Kevin McMurtrie
    Jun 19, 2004
  5. Bob Greschke

    Tkinter Text widget incremental search

    Bob Greschke, Sep 28, 2006, in forum: Python
    Replies:
    0
    Views:
    444
    Bob Greschke
    Sep 28, 2006
Loading...

Share This Page