Entry
Is there a way to make a text box uneditable by the user, but insertable ( insert(END, 'schweet') ) by the application?
Sep 27th, 2002 11:31
Greg Goodman, unknown unknown, richard_chamberlain
There may be a better way of doing it...
from Tkinter import *
root=Tk()
text=Text(root,width=50,height=50)
text.pack()
def intercept(event):
return 'break'
text.bind('<Key>',intercept)
text.insert(END,'Sweet ;-)')
root.mainloop()
Here I bind a <Key> event to the intercept function - where I return
'break' to stop the event propagating, so basically it's disabled. To
undisable you'd just need to unbind that event.
---
You could create a disabled Text widget and bracket the programmatic
text insertion with calls to enable/disable the widget:
from Tkinter import *
root = Tk()
w = Text(root, width=50, height=5, state=DISABLED)
w.pack()
def do_insert():
w.configure(state=NORMAL)
w.insert(END, 'more text...')
w.configure(state=DISABLED)
Button(root, text='insert', command=do_insert).pack()
root.mainloop()