0

I have the following function:

def some_search(event):
    print userSearch.get()

And I've set the function to run whenever the user types in the entry field using the below code:

userSearch.bind("<Key>", some_search)

My problem is that userSearch.get() doesn't return what's actually in the entry field.

For example, if "test" is in the entry field, the function prints "tes".

If "Hello World" is in the entry field, the function prints "Hello Worl".

Sorry if this is a stupid question, I'm fairly new to programming, I suspect the answer will be a simple one.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Justin
  • 37
  • 9

2 Answers2

0

The event occurs before the keypress has affected the entry. You will need to take the char and keysym attributes of the event object and apply them to the entry contents.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

Change the binding method from "<Key>" to "<KeyRelease>"

Steven Summers
  • 5,079
  • 2
  • 20
  • 31