0

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Cubi73
  • 1,891
  • 3
  • 31
  • 52

1 Answers1

2

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

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Worth noting there are other ways in which further validation can be cancelled, in particular, [this](http://stackoverflow.com/questions/1019782/python-tkinter-entry-fun). Not directly relevant to this question but a common and difficult to find problem with validation. – strubbly Oct 23 '15 at 07:24