是否可以使Tkinter中的Text小部件不可点击和不可编辑?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.