Consider the following code:
#!/usr/bin/env python3
from tkinter import *
from tkinter.ttk import *
root = Tk()
entry = Entry(root)
entry.bind('<Key>', lambda e: print(entry.get()))
entry.grid()
Button(text="Close", command=root.destroy).grid()
root.mainloop()
It prints the text in the entry
input box every time a key is pressed, so why does it print the text as it was one key before?
I suspect it is because the entry.get()
is run before the key is added to the input box. Is there a way around this?
Example:
When I type the following, one key at a time:
Python
the following is printed
Pytho