hi all,
how to put a restriction for the number of characters to be entered on an entry widget? When I'm using the attribute -width 4 it's just alters the size but not the number!!
thanq.
There isnt an option to limit the # of characters entered. What you'll need to do is put a keystroke bind on that entry widget. The bind should call a function that checks the length of the contents of the entry widget, if the contents is too long then remove the last character. If the bind is in place, the user will never be able to exceed your set width.
It's really the same thing but the entry widget has a "-validate" option and a "-validatecommand" option. They allow you to specify a script (proc) to use to check the entry data.
Note that the -validate and -validatecommand options were added to entry widgets as of Tcl/Tk 8.3. So, if you're working with an earlier version, you'll need to accomplish the validation through bindings, as smugindividual suggested. But here's an example of how to use the built-in entry validation mechanism that Bong suggested:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.