Tkinter Label

Tkinter Label Widget

Tkinter Label is a widget which is used to display text or images in a Tkinter graphical user interface.

In the following GUI screenshot, the text Hello World! is displayed using a Label widget.

Tkinter Label

In this tutorial, you will learn how to create a Label widget and display it in a window.

Steps to create and display Label in Tkinter

Step 1

Import tkinter and create a window.

import tkinter as tk
window = tk.Tk()

Step 2

Create a label widget using tkinter.Label class.

label = tk.Label(window, text="Hello World!")

The first argument to the Label() constructor specifies the master for the Label widget. Since we are going to display the Label directly in the window, we pass window object created in the previous step.

Step 3

Pack the label widget in the parent widget using Label.pack() method.

label.pack()

Step 4

Run the application.

window.mainloop()

Example

In this example, we shall combine all the above mentioned steps, and create a Label with text Hello World.

Program

import tkinter as tk

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

# Create a label widget
label = tk.Label(window, text="Hello World!")

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

# Run the application
window.mainloop()

Output

Run on a MacOS.

Tkinter Label - Example

Summary

In this Python Tkinter tutorial, we learned how to create a Label widget and display it in the window, with examples.

Code copied to clipboard successfully 👍