How to make text widget skip to next line when row is full with scrollbar in Tkinter

601 Views Asked by At

I am new to programming in general and to Tkinter. I am trying to use scrollbar with text-widget, and I get the scrollbar working just fine. However the text on the widget does not change line when the row is full of text.

In the picture (Picture) the image above is what I am talking about. Bellow image is how I would like the text to act to act inside the tex-widget, but with scrolbar added. On the picture bellow I can scroll by selecting the text and draging it down whitch is not ideal. Both pictures (in the picture) are query from the excact same database entry.

Here is my relevant code for the picture with the scrollbar:

selite_frame = Frame(hakutulos_frame)
selite_frame.grid(row=2, column=0, columnspan=3)
selite_text = Text(selite_frame, borderwidth=5, width=52, height=5, bg=colour5, relief="groove")
selite_text.insert(END, data[row_count][5])
selite_text.pack(side="left")
selite_text.configure(state=DISABLED)

Sorry for variables and some of the text not being in english. It is not my naitve language.

2

There are 2 best solutions below

2
On BEST ANSWER

Even though you didn't provide a proper example, it appears that the wrap option on the widget has been turned off even though it is usually turned on by default.

You just need to set the wrap option to either the string "word" or "char".

the_widget.configure(wrap="word")
0
On

I don't understand your question but I think your problem would be avoided if you just used the standard scrolled text object instead of making your own.

from tkinter.scrolledtext import ScrolledText
selite_frame = Frame(hakutulos_frame)
selite_frame.grid(row=2, column=0, columnspan=3)
selite_text = ScolledText(selite_frame, borderwidth=5, width=52, height=5, bg=colour5, relief="groove")
selite_text.insert(END, data[row_count][5])
selite_text.pack(side="left")
selite_text.configure(state=DISABLED)