
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to word-wrap text in Tkinter Text?
Word Wrapping plays a significant role in any textual information. It is an important feature for any text editor which breaks the section of a particular text to fit into multiple sections of lines where possible. It is used to fit the content in the width of a text document. In Tkinter, we can wrap the words or chars in the text widget using the wrap property. The default values for the wrap properties are – WORD, CHARS, or NONE.
Example
In this example, we will wrap all the words of a text widget using the wrap property.
#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Create a text widget and wrap by words text= Text(win,wrap=WORD) text.insert(INSERT,"Python is an interpreted, high-level and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation.") text.pack() win.mainloop()
Output
Running the above code will display a window containing some text. The text is wrapped by words which helps the user to read the document or text file easily.
- Related Articles
- How can we implement line wrap and word wrap text inside a JTextArea in Java?
- How to wrap the text in text flow layout in JavaFX?
- How to highlight text in a tkinter Text widget?
- Adding coloured text to selected text in Tkinter
- How to wrap the text of a label in JavaFX?
- How to insert text at the beginning of the text box in Tkinter?
- How do I center the text in a Tkinter Text widget?
- Wrap Strings of Text in Bootstrap Navbar
- How To Dynamically Resize Button Text in Tkinter?
- How to set font for Text in Tkinter?
- How to change text cursor color in Tkinter?
- How to get the Tkinter Label text?
- How to take input in a text widget and display the text in tkinter?
- How to get the current length of the Text in a Tkinter Text widget?
- How to create hyperlink in a Tkinter Text widget?

Advertisements