I have an Entry widget with a StringVar as a text variable. I use
input_content.trace_id = input_content.trace_add("write", solve)
to run solve()
each time the content of the Entry widget changes.
I would like to be able to determine what key did the user press that ran the solve function.
Entry().bind()
doesn't work for me because it seems that the entry is not updatted in time (Say I type Python, when using .bind()
to get the content of the Entry, it will output Pytho). Please refer to the code below that demonstrates this behaviour:
from tkinter import*
master = Tk()
def main(event):
print(f"Inputted character: {event.keysym}")
print(f"{entry.get() = }")
print(f"{entry_var.get() = }")
entry_var = StringVar()
entry = Entry(master, textvariable=entry_var)
entry.pack()
entry.bind("<Key>", main)
mainloop()
As you can see, I'm able to get the last inputted character using event.keysym
but the entry is not updated until main()
is run again, etc.
I would like to have both the last inputted character and have the entry content updated when the function is run.