tags:

views:

58

answers:

1

Hi,

i am using tkinter in python and would like to add an event to an Entry widget. I would like it to wait for text to be typed into it and then perform the action when text is typed.

something to the effect of:

self.entry(command=self.event)

is there anyway to do this?

+1  A: 

You didn't specify how do you decide that the user has finished typing. You can:

  • Use timeout - check how much time has passed between two letters and process input if the delay is longer than, say 3 seconds. Your typical user will not like this solution, but it would seem that is what you are after. The way to do this:

    1. "define" your StringVar: s = Tkinter.StringVar(root)
    2. assign callback for writing to your StringVar: s.trace('w', handle_input)
    3. handle delay checking and useful code in your *handle_input* callback
    4. when creating Entry widget, pass in your StringVar as textvariable: e = Tkinter.Entry(root, textvariable=s)
  • Use enter key when finished typing - bind "<Enter>" event to Entry widget:

    e.bind('<Enter>', handle_input)
    
Josip