Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10265
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Validating Entry in tkinter |
| Followup-To | comp.lang.python |
| Date | 2011-07-25 14:31 +0200 |
| Organization | None |
| Message-ID | <j0jnmc$r8j$1@solani.org> (permalink) |
| References | <745ebc09-7233-4718-8a01-d49d2075c4d9@glegroupsg2000goo.googlegroups.com> |
Followups directed to: comp.lang.python
Saul Spatz wrote:
> That doesn't work, I'm being stupid, The user might type anywhere in the
> string, not just at the end. I need
>
> return all([c in '1234567890abcdefABCDEF ' for c in after])
Ah, you found out already. Here's what I've come up with in the meantime.
I also changed the command to a tuple as in the example pointed out by
Wolfgang.
import tkinter as tk
def is_valid_fromhex(s):
for pad in "", "0":
try:
bytes.fromhex(s + pad)
except ValueError:
pass
else:
return True
return False
def validate(before, after):
print(before, "-->", after)
return is_valid_fromhex(after)
if __name__ == "__main__":
root = tk.Tk()
cmd = (root.register(validate), "%s", "%P")
entry = tk.Entry(root, validate="all", validatecommand=cmd)
entry.pack()
entry.focus_set()
root.mainloop()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Validating Entry in tkinter Saul Spatz <saul.spatz@gmail.com> - 2011-07-25 05:12 -0700
Re: Validating Entry in tkinter Peter Otten <__peter__@web.de> - 2011-07-25 14:31 +0200
Re: Validating Entry in tkinter Terry Reedy <tjreedy@udel.edu> - 2011-07-25 13:24 -0400
Re: Validating Entry in tkinter Peter Otten <__peter__@web.de> - 2011-07-25 21:08 +0200
Re: Validating Entry in tkinter rantingrick <rantingrick@gmail.com> - 2011-07-25 12:55 -0700
Re: Validating Entry in tkinter python@bdurham.com - 2011-07-25 16:26 -0400
Re: Validating Entry in tkinter Peter Otten <__peter__@web.de> - 2011-07-25 23:03 +0200
Re: Validating Entry in tkinter "Malcolm Greene" <mgreene@bdurham.com> - 2011-07-25 17:54 -0400
csiph-web