- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements