limiting text input in Tkinter Entry widget

Otto Krüse otto_kruse at hotmail.com
Sun Feb 22 11:20:33 EST 2004


Hi everyone,

I'm building a GUI in which I want, amongst other things, for people to 
fill in there postal code. The postal codes of my country (Holland) are 
in this format: 1234 AB

So for the input I use two entry widgets, one of a length of 
(characters) for the numbers and one of lenght 2 for the letters. What I 
don't like is that although the visible part of the widgets thus are 4 
and 2 characters, users can actually input more characters. They could 
for example input 12345 abcd. I want to make that impossible.

Does anyone know a way to limit the amount of characters an entry widget 
can take? Is there an easy option to set for this or does this problem 
require some python code? Can't seem to find answers in any documentation.

The code:
self.e1 = Entry(frame, width="4")
self.e2 = Entry(frame, width="2")

Thanks a lot,
Otto



More information about the Python-list mailing list