简体   繁体   English

如何将文本添加到禁用的Tkinter文本小部件?

[英]How to add text to a disabled Tkinter Text widget?

I'm aware of the fact that text widgets are disabled using widget.config(state = tk.DISABLED) , making the user unable to change the content of the widget. 我知道以下事实:使用widget.config(state = tk.DISABLED)禁用了文本小部件,这使用户无法更改小部件的内容。 Content can be added before this statement is run using widget.insert(tk.END, text-to-add) , but after that you'd have to alternate between the NORMAL and DISABLED states to add text content, using a command like this: 可以在使用widget.insert(tk.END, text-to-add)运行此语句之前添加内容,但是在那之后,您必须使用类似这样的命令在NORMALDISABLED状态之间交替以添加文本内容:

def add_text(widget, text):
   widget.config (state = tk.NORMAL)
   widget.insert (tk.END, text)
   widget.config (state = tk.DISABLED)

Is there any other, more efficient way to do that? 还有其他更有效的方法吗?

Is there any other, more efficient way to do that? 还有其他更有效的方法吗?

No, there is not. 不,那里没有。 That is the most efficient way to do what you want. 这是做您想要的事的最有效方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM