Error in 2.2.1 Tkinter? (was: limiting text input in Tkinter Entry widget)

Peter Otten __peter__ at
Mon Feb 23 08:37:49 CET 2004

Cameron Laird wrote:

[Doesn't work:]

>>  def validate(name, index, mode):
>>    value = root.getvar(name)
>>      # Truncate the entry text to its first four characters.
>>    root.setvar(name, value[0:4])
>>  my_variable = Tkinter.StringVar()
>>  my_variable.trace_variable('w', validate)


>   def validate(name, index, mode):
>     value = my_variable.get()
>     my_variable.set(value[0:4])

A look into reveals that Variable.set()/get() is implemented in
terms of tkapp.globalsetvar()/globalgetvar(). Translating it into your

def validate(name, index, mode):
    value =, value[0:4])

So the problem seems to relate to different Tcl namespaces. I didn't dig any


PS: I used Python 2.3.3

More information about the Python-list mailing list