How to disable input to a Text widget but allow programatic input?

后端 未结 3 1505
夕颜
夕颜 2021-02-20 01:52

How would i go about locking a Text widget so that the user can only select and copy text out of it, but i would still be able to insert text into the Text

3条回答
  •  伪装坚强ぢ
    2021-02-20 02:27

    Sorry I'm late to the party but I found this page looking for the same solution as you.

    I found that if you "disable" the Text widget by default and then "normal" it at the beginning of a function that gives it input and "disable" it again at the end of the function.

    def __init__():
        self.output_box = Text(fourth_frame, width=160, height=25, background="black", foreground="white")
        self.output_box.configure(state="disabled")
    
    def somefunction():
        self.output_box.configure(state="normal")
        (some function goes here)
        self.output_box.configure(state="disable")
    

提交回复
热议问题