Set Border of Tkinter Label Widget

In this tutorial, we will introduce how to set the border of the Tkinter Label.

Tkinter Label doesn’t have the border by default as shown below.

Tkinter Label_no border

You need to assign the borderwidth option to add a border around Label widget, and also assign the relief option to be any option rather than flat to make border visible.

         borderwidth = 3,
         text="sunken & borderwidth=3")

It sets the borderwidth as 3 and border decoration option relief to be sunken.

The below example shows the label order with different relief options.

Tkinter Label set border

As you could see, the border is invisible when the relief is flat (default relief value), even when the borderwidth is set.

Complete Working Code Example

import tkinter as tk
app = tk.Tk()

labelExample1 = tk.Label(app,
                        borderwidth = 1,
                        width = 40,
                        text="raised & borderwidth=1")
labelExample2 = tk.Label(app,
                        borderwidth = 2,
                        width = 40,
                        text="ridge & borderwidth=2")
labelExample3 = tk.Label(app,
                        borderwidth = 3,
                        width = 40,
                        text="sunken & borderwidth=3")
labelExample4 = tk.Label(app,
                        borderwidth = 4,
                        width = 40,
                        text="flat & borderwidth=4")
labelExample5 = tk.Label(app,
                        borderwidth = 5,
                        width = 40,
                        text="groove & borderwidth=5")
labelExample6 = tk.Label(app,
                        borderwidth = 6,
                        width = 40,
                        text="solid & borderwidth=6")

labelExample1.grid(column=0, row=0, padx=10, pady=10)
labelExample2.grid(column=0, row=1, padx=10, pady=10)
labelExample3.grid(column=0, row=2, padx=10, pady=10)
labelExample4.grid(column=0, row=3, padx=10, pady=10)
labelExample5.grid(column=0, row=4, padx=10, pady=10)
labelExample6.grid(column=0, row=5, padx=10, pady=10)
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Tkinter Label

  • Hide, Recover and Delete Tkinter Widgets