ScrolledText (over Tkinter.Text) validation
Phlip
phlip_cpp at yahoo.com
Mon May 20 13:39:00 EDT 2002
Hypo Nt:
I require a multi-line Text field with validation. It should, at
least, bounce graphic characters outside a small range. After much
messing with the options I have settled on this unhappy medium:
from Tkinter import *
def valid(vent):
if vent.keysym_num > 255: return
if vent.char not in "PERU":
text = vent.widget
text.event_generate('<Key-BackSpace>')
return
aText = Text()
aText.bind('<KeyRelease>', valid)
aText.pack()
mainloop()
Efforts to be more exact left the cursor in the wrong location,
or prevented copy-n-paste, or didn't work.
The problem with that code is it fails the chimp-test. If you bang
the keyboard you can insert characters faster than that recursive
I have liked to have intercepted the KeyPress event and removed
the character before it went in, but the 'event' object was one-way.
Does anyone have a better method?
--
Phlip
More information about the Python-list
mailing list