1

I have an issue with the Event-Handling. My Code is as follows:

import tkinter

def my_function(event):
    print("Event Char: " + event.char)
    print("Input Field: " + my_input.get())

window = tkinter.Tk()
my_input = tkinter.Entry()
my_input.bind("<Key>", my_function)
my_input.grid(row=0, column=1)

window.mainloop()

If I run my programm and enter the letters a, b , c in sequence, then my prints are, as follows: Console Output

I do not understand why my_input is lagging behind. Is this a bug? How can I fix this?

Thx in advance

j_4321
  • 15,431
  • 3
  • 34
  • 61
YagmurG
  • 25
  • 3

1 Answers1

1

This is not a bug: The event is triggered before the new character is inserted in the entry field, which is why the entry content is "lagging behind".

To fix this, bind instead to <KeyRelease> which is triggered after the character is inserted in the entry field.

j_4321
  • 15,431
  • 3
  • 34
  • 61