Tkinter text entry questions: set_text, onchange.
dirk at gerrits.homeip.net
Wed Apr 23 22:59:26 CEST 2003
I've been creating a little GUI application with Python 2.3a2 and
Tkinter and I've been running into some issues with Entry widgets.
I have some of them with state='readonly', and I want to update their
text values from Python functions. For reading their text values there
is the simple method .get(), but there doesn't seem to be a
corresponding .set() method? So I've tried using delete followed by
insert, but this doesn't seem to work for state='readonly'. Finally, I
made the following helper function:
def set_text(entry, text):
old_state = entry["state"]
entry["state"] = "normal"
entry["state"] = old_state
This seems to do the trick, but it seems to me that it's a lot more
trouble then necessary. Isn't there a more obvious, more 'pythonic'
Also, I have some state='normal' Entry widgets for which I want to call
a function whenever their value changes. Currently, I use the following
helper function, but just as with set_text, I feel it is a non-obvious hack:
def bind_onchange(entry, command):
for sequence in ["<Key>", "<KeyPress>", "<KeyRelease>"]:
Is there a better solution for this (too)?
Thanks in advance,
More information about the Python-list