Jovito Jovito - 2 months ago 16
Python Question

Is there a way to make a Text widget in Tkinter non-clickable and non-editable?

Is it possible do make a Text widget in Tkinter non-clickable and non-editable?

Answer

Just set its state to "disabled":

from Tkinter import Tk, Text, DISABLED
r = Tk()
Text(r, state=DISABLED).grid()
r.mainloop()

You can even enter some text before you disable it.

from Tkinter import Tk, Text, DISABLED
r = Tk()
t = Text(r)
t.grid()
t.insert(0.0, "BLAH!")
# Just make sure you disable it AFTER you put the text in
t["state"] = DISABLED
r.mainloop()

Then I suppose you could set its background to be grey or something so that people know it is inactive.

Edit:

Since you asked, you can reactivate the textbox like this:

# Note you have to have NORMAL imported
t["state"] = NORMAL