Tkinter Label – Wrap Text

Tkinter – Wrap text in Label widget

In Tkinter, you can wrap the text in a label widget to specific screen units.

Tkinter Label - Wrap text to wraplength=200
Tkinter Label – Wrap text to wraplength=200

To wrap the text in a label widget to specific screen units in Tkinter, call specify required number of screen units for the the wraplength parameter while creating the Label widget using tk.Label().

tk.Label(window, wraplength=200, text="")

In this tutorial, you will learn how to wrap the text in a label widget in Tkinter, with an example program.

Example

Consider a simple use case where you would like to display some large text in a Label widget, and wrap the text in a length of 200 screen units.

Python Program

import tkinter as tk

# Create the main window
window = tk.Tk()
window.geometry("300x200")
window.title("PythonExamples.org")
window.configure(padx=5, pady=5)

label = tk.Label(window, wraplength=200, text="This is a sample text to visulaize the wrapping of text in a label widget.")
label.pack()

# Run the application
window.mainloop()

Output in Windows

Output in MacOS

Tkinter Label - Wrap Text - Example
Tkinter Label – Wrap text to wraplength=200

Summary

In this Python Tkinter tutorial, we learned how to wrap the text in a Label widget in Tkinter, with examples.

Related Tutorials

Code copied to clipboard successfully 👍