Reputation:
How do you word-wrap text in a Tkinter Text
widget? wraplength
only takes in screen units, and not a WORD
option.
Upvotes: 19
Views: 30823
Reputation: 87054
Use the wrap=WORD
option. Here's an example:
from tkinter import *
root = Tk()
t = Text(wrap=WORD)
t.pack()
root.mainloop()
Alternatively you can set a value for wrap
using Text.config()
:
t = Text()
t.config(wrap=WORD)
The other valid values for wrap
are CHAR
which is the default, or NONE
in which case no wrapping occurs and the line will grow indefinitely.
Upvotes: 33