Disabling user from deleting text in tkinter scrolledtext

女生的网名这么多〃 提交于 2020-01-30 03:15:27

问题


If this has already been posted and answered I couldn't find it by searching. I am trying to use a tkinter scrolledtext widget to serve as a basic text display for file operations the script I'm writing will perform. Why would I want to do this? I don't like how the terminal limits how far you can scroll, how it looks, and I think this looks much more streamlined into a simple GUI.

I know we can create a simple scrolledtext widget like so and also disable user input and deleting with setting the state to state = disabled. Since these is just serving as a text area to display essentially what's happening I don't need any input from the user merely a read-only interface. However, setting the state to disabled prevents insert from being used to insert the updates themselves.

Is there a way around this? Simpler alternative methods are also welcome. I could use a label, but then I'd have scrolling issues.

I realize I could change the state before and after inserting, from normal to disabled, but seems like there should be a simpler solution.

  text_area = ScrolledText(master = root, wrap = tk.WORD, state = tk.DISABLED)
  text_area.pack(side = tk.TOP, fill = tk.BOTH, expand = True)
  text_area.insert(tk.INSERT, some_text_here) #No longer works

回答1:


Setting the state from disable to normal, inserting text, and setting it back to disabled, is the simplest solution.



来源:https://stackoverflow.com/questions/31355376/disabling-user-from-deleting-text-in-tkinter-scrolledtext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!