Sep-22-2020, 11:26 PM
I misunderstood your OP and thought you wanted to wait until all text was entered before starting search. Instead you want to search all the text that is in the entry field.
As you have discovered, this is difficult to do binding to the key event. The key event is really meant to be used to intercept a key press before it is processed. You want to call something after the key press is processed. To do that I suggest you use "trace".
As you have discovered, this is difficult to do binding to the key event. The key event is really meant to be used to intercept a key press before it is processed. You want to call something after the key press is processed. To do that I suggest you use "trace".
from tkinter import * def search(var, index, mode): label_text.set(entry_text.get()) root = Tk() root.geometry('220x80') label_text = StringVar() label = Label(root, textvar=label_text) label.place(x=10, y=10, width=200) entry_text = StringVar() entry_text.trace_add('write', search) entry = Entry(root, textvar = entry_text) entry.place(x=10, y=50, width=200)In this example the search() function is called when the "entry_text" variable is written. This happens after the key press event and after the latest key is added to the entry text.