Search code examples
tkinterpython-3.4textchangedtkinter-entry

TextChanged/KeyDown for Entry/TextBox


I wrote following script based on this post:

from tkinter import *

class MainWindow(Tk):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.geometry("500x300+433+234")
        self.title("Hallo")

        self.__tbIn_Txt = StringVar(None, "Hallo")
        self.__tbIn = Entry(self, textvariable = self.__tbIn_Txt, validate = "all")
        self.__tbIn.config(validatecommand = (self.register(self.__check),))
        self.__tbIn.pack()

    def __check(self):
        print("Check")

    def show(self):
        self.mainloop()

wMain = MainWindow()
wMain.show()

__check fires only the first time I click the Textbox/Entry, but never again. I want to achieve a KeyDown/KeyUp/KeyPress/TextChanged behavior, but it seems that my script results in a OnClick event. How to make the textbox call __check for every change in the Entry's value?

I am running Python 3.4 (64-bit) on Windows 7 64-bit.


Solution

  • The validatecommand must return True or False, or tkinter will cancel further validation.