1 Oct 2008 05:15
validation woes
Jeff Cagle <jrcagle <at> juno.com>
2008-10-01 03:15:23 GMT
2008-10-01 03:15:23 GMT
I want an Entry widget to accept a single digit only. Here's the attempt:
---
import Tkinter as Tk
class MyEntry(Tk.Entry):
def __init__(self, parent, **kwargs):
kwargs['validate']='key' # could also be 'all' -- has the
same result
kwargs['vcmd']=self.validate
Tk.Entry.__init__(self, parent, **kwargs)
def validate(self):
print self.get() # diagnostic only
if self.get() in [''] + list("123456789"):
return True
else:
self.bell()
return False
if __name__=="__main__":
main = Tk.Tk()
main.e = MyEntry(main)
main.e.grid()
main.mainloop()
---
I'd like to think this is straightforward, but No.
(Continue reading)
RSS Feed