The Wayback Machine - https://web.archive.org/web/20250602062807/https://www.geeksforgeeks.org/how-to-make-a-label-bold-tkinter/
Open In App

How To Make A Label Bold Tkinter?

Last Updated : 23 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Tkinter has various customization settings that allow you to modify the appearance of GUI elements, including labels. Making a label bold can be achieved using different methods, such as configuring the font directly or using styles. In this article, we will explore different approaches to make a label bold in tkinter.

Make A Label Bold in Tkinter

Below are the possible approaches to make a label bold in Tkinter in Python:

  • Using Label.config() Method
  • Using Style with ttk
  • Using a Custom Label Class

Make A Label Bold in Tkinter Using Label.config() Method

In this approach, we are using the Label.config() method to make the label text bold. We first create a label and then use the config() method to set the font option to a tuple specifying the font family (Helvetica), size (12), and weight (bold). This updates the label to display bold text.

Python
import tkinter as tk
root = tk.Tk()
root.title("Bold Label Example1 ")
label = tk.Label(root, text="Hello GFG - Message 1 ")
label.config(font=("Helvetica", 12, "bold"))
label.pack(pady=20)
root.mainloop()

Output:

Ex1

Make A Label Bold in Tkinter Using Style with ttk

In this approach, we are using the ttk.Style class to create a custom style for the label. We configure the style named "Bold.TLabel" with a bold font by setting the font option to ("Helvetica", 12, "bold"). This style is then applied to the ttk.Label, making its text bold.

Python
import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.title("Bold Example 2")
style = ttk.Style()
style.configure("Bold.TLabel", font=("Helvetica", 12, "bold"))
label = ttk.Label(root, text="Hello GFG - Example 2", style="Bold.TLabel")
label.pack(pady=20)
root.mainloop()

Output:

Ex2

Make A Label Bold in Tkinter Using a Custom Label Class

In this approach, we define a custom BoldLabel class that inherits from tk.Label. The constructor of BoldLabel creates a bold version of the existing font and applies it to the label. This custom class allows for easy creation of bold labels.

Python
import tkinter as tk
from tkinter import font

class BoldLabel(tk.Label):
    def __init__(self, master=None, **kwargs):
        super().__init__(master, **kwargs)
        bold_font = font.Font(self, self.cget("font"))
        bold_font.configure(weight="bold")
        self.configure(font=bold_font)

root = tk.Tk()
root.title("Bold Label Example 3")

label = BoldLabel(root, text="Hello GFG - Example 3", font=("Helvetica", 12))
label.pack(pady=20)

root.mainloop()

Output:

Ex3

Next Article
Article Tags :
Practice Tags :

Similar Reads