
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use Tkinter to Create Line-Wrapped Text in Python
Tkinter provides Text widget to input data in a text field. It can accept multiline user input. Tkinter includes many inbuilt properties and features that can be used to improve the look and feel of the context. The text written in Text widget can be wrapped with wrap property. The wrap allows users to simplify the text editor by wrapping the context in words, characters or None. It fixes the indentation of the text inside the Text Editor.
Example
In this example, we will wrap the sentences by words which means each word gets selected automatically without following the same line.
# Import the required libraries from tkinter import * from lorem_text import lorem # Create an instance of tkinter frame win = Tk() win.geometry("700x350") # Add a text widget and fill with lorel Ipsum generator paragraphs size= 5 text = Text(win, wrap="word") text.insert(END, lorem.paragraphs(size)) text.pack() win.mainloop()
Output
Running the above code will display a window with some text in a text widget. The content written inside the text widget is wrapped by words.
Advertisements