0

as said in the title I would like that each time a character is typed in a certain entry, a function is called. i tried this :

f = Tk()
f.geometry("600x600+600+100")

svar = StringVar()
svar.set("Pokemon 1")

def test(self,mode,callback):
    print(svar[0].get())

svar.trace_variable("w", test)

def test():
    print(svar.get())

entry = Entry(f, textvariable = svar, justify = "center", bg = "white")
entry.place(anchor = "nw", x = 5+x*320, y = 30, width = 270, height = 25)

f.mainloop()

i dont understand the "self" "mode" "callback" and "w"

anpawo
  • 19
  • 3
  • Is this what you are looking for? https://stackoverflow.com/questions/4140437/interactively-validating-entry-widget-content-in-tkinter – DwightFromTheOffice Jun 25 '21 at 15:13
  • 1
    Assign a `StringVar` to it and then use `trace` method on it – Delrius Euphoria Jun 25 '21 at 15:25
  • dwight, it may be that but i don't know how to use self, so i don't understand all... but thanks for the answer – anpawo Jun 25 '21 at 15:59
  • cool cloud, thanks for your answer, i think trace is the answer and it should work. but i dont understand the arguments you need to put in it – anpawo Jun 25 '21 at 17:06
  • Part of the problem is that `validatecommand = test()` needs to be `validatecommand = test`, and `test` must return `True` or `False` or it will automatically be disabled. – Bryan Oakley Jun 25 '21 at 17:26
  • Are you wanting to call this function to perform validation, or is it doing something else such as logging or configuring other widgets? – Bryan Oakley Jun 25 '21 at 17:27
  • I would like a listbox to display different things depending on what is in the entry. What you just told me works but the problem is that the last letter is missing on the print. – anpawo Jun 25 '21 at 18:01
  • Yes, it's missing the last letter because validation happens before the character is inserted, because it's designed for validation. It's designed so that you can prevent characters from being inserted, which can only happen before the character is inserted. There are ways around it, but if you're not actually doing validation, the validatecommand isn't the proper way to do it. – Bryan Oakley Jun 26 '21 at 04:23
  • ok. so i tried with trace and it works but i didn't understand the mode and the callback. i'm going to change the program above, look at it to give me your opinion. – anpawo Jun 26 '21 at 09:06

0 Answers0