Tkinter Label Italic Text

Tkinter Label italic text

To set the italic font of a Label widget in Tkinter, create a Font object with the slant parameter of Font() constructor set to “italic”, and pass this font object as argument to the font parameter of Label() constructor.

Tkinter Label italic text

In this tutorial, you will learn how to set the font of a Label widget to italic, with examples.

Steps to set italic text for Label in Tkinter

Step 1

Import font from tkinter library, and create a Font class object with italic font.

from tkinter import font
label_font = font.Font(slant="italic")

Step 2

Create a label widget using tkinter.Label class constructor and pass the label_font as argument to the font parameter.

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

Examples

1. Label with italic font

In this example, we shall create a Label with text Hello World and font set to italic, and display it in the main window.

Program

import tkinter as tk
from tkinter import font

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

# Create font object
label_font = font.Font(slant="italic")

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

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

# Run the application
window.mainloop()

Output

Run on a MacOS.

Tkinter Label italic text - Example

Summary

In this Python Tkinter tutorial, we learned how to create a Label widget with italic text, with examples.

Code copied to clipboard successfully 👍