entry widget won't validate

Mike hennebry at web.cs.ndsu.nodak.edu
Tue Sep 22 12:48:23 EDT 2009


On Sep 22, 4:29 am, Peter Otten <__pete... at web.de> wrote:
> Mike wrote:
> > On Sep 21, 12:47 pm, Peter Otten <__pete... at web.de> wrote:
> >> Mike wrote:
> >> > I'm trying to arrange for an Entry widget to check whether its data
> >> > is all digits and whether the number represented is small enough.
> >> > The validate function seem to be called once at startup and not
> >> > afterwards:
>
> >> > The print statement run 3 times at startup.
> >> > Editing an Entry does not cause any printing.
> >> > Any ideas?

> I don't know Tcl either; the following is the first thing that seemed to
> work, after some trial and error:
>
> import Tkinter as tk
>
> def validate(before, after):
>     print before, "-->", after
>     return after.isdigit()
>
> if __name__ == "__main__":
>     root = tk.Tk()
>     name = root.register(validate)
>     cmd = 'expr {[%(name)s %(parms)s]}' % dict(name=name, parms="%s %P")
>     var = tk.StringVar()
>     entry = tk.Entry(root, textvariable=var,
>                      validate="all", validatecommand=cmd)
>     entry.pack()
>     entry.focus_set()
>     root.mainloop()

Thanks.
It worked.
I discovered that None is not an acceptable substitute for False.
If validate returns None, it quits being called.



More information about the Python-list mailing list