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

后端 未结 3 1532
夕颜
夕颜 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:39

    I stumbled upon the state="normal"/state="disabled" solution as well, however then you are unable to select and copy text out of it. Finally I found the solution below from: Is there a way to make the Tkinter text widget read only?, and this solution allows you to select and copy text as well as follow hyperlinks.

    import Tkinter
    
    root = Tkinter.Tk() 
    readonly = Tkinter.Text(root)
    readonly.bind("", lambda e: "break")
    

提交回复
热议问题