Reputation: 335
I am well aware that a scrollbar can be added to a Text widget. but my problem is i want it read only.The only way i can do is by making the state=DISABLED, but this will block my text, hence cant copy the text. Well in the Tkinter Entry widget there is no yScroll behavior. Any idea how i can get these things worked? Any help is appreciated.
Right now i am using this for Text
`
root=Tk()
txt = Text(root, height=5, width=55)
scr = Scrollbar(root)
scr.config(command=txt.yview)
txt.config(yscrollcommand=scr.set)
txt.pack(side=LEFT)
txt.insert(INSERT, "hello world\nhello world\n hello world\n hello world\n hello world\n hello world\n hello world\n hello world\n hello world\n hello world\n")
txt.insert(END,"\n")
scr.pack(side="right", fill="y", expand=False)
txt.pack(side="left", fill="both", expand=True)
root.mainloop()
`
with this the problem is that the text can be edited.
Upvotes: 0
Views: 4592
Reputation: 386352
The reason you can't seem to copy the text of a disabled widget is that the disabled widget on some platforms does not get focus, and focus is required to select text. You can rectify that by adding a binding to set the focus on a mouse click.
Add the following two lines to your code:
txt.configure(state="disabled")
txt.bind("<1>", lambda event: txt.focus_set())
Upvotes: 1