Tkinter Label – Width and Height

Tkinter Label – Width and Height

You can set the width of a Label widget in Tkinter to specific number of characters and the heigh of the Label widget to a specific number of lines.

Tkinter Label - Width and Height
Tkinter Label width=30 and height=5

To set the width of a Label widget to specific number of characters, pass the required number as integer value as argument for the width parameter in the Label() constructor.

width=20

To set the height of a Label widget to specific number of lines, pass the required number as integer value as argument for the height parameter in the Label() constructor.

height=3

In this tutorial, you will learn how to set the width and height of a Label widget in Tkinter, with examples.

Examples

1. Label of 20 characters wide and 3 lines height

In this example, we shall create a Label with a width of 20 characters, and a height of 3 lines.

We have set the background color, so that we can see the whole Label widget dimensions.

Program

import tkinter as tk

# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")

# Create a label widget with specific font
label = tk.Label(window, text="Hello World!", width=20, height=3, bg="lightgreen")

# Pack the label widget to display it
label.pack()

# Run the application
window.mainloop()

Output

Tkinter Label – Width and Height

Run on a MacOS.

Tkinter Label - Width and Height set to 20 and 3 respectively

2. Label of 30 characters wide and 5 lines height

In this example, we shall create a Label with a width of 30 characters, and a height of 5 lines.

Program

import tkinter as tk

# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("300x200")

# Create a label widget with specific font
label = tk.Label(window, text="Hello World!", width=30, height=5, bg="lightgreen")

# Pack the label widget to display it
label.pack()

# Run the application
window.mainloop()

Output

Tkinter Label – Width and Height

Run on a MacOS.

Tkinter Label - Width and Height set to 30 and 5 respectively

Summary

In this Python Tkinter tutorial, we learned how to set a specific width and height for a Label widget, with examples.

Related Tutorials

Code copied to clipboard successfully 👍