Uzzee Uzzee - 3 months ago 38
Python Question

Border for tkinter Label

Not really relevant but i'm building a calendar and I have a lot of Label widgets, and therefore it will look alot nicer if I had some borders for them!

I have seen you can do this for other widgets such as Button, Entry and Text.

Minimal code:

from tkinter import *

root = Tk()

L1 = Label(root, text="This")
L2 = Label(root, text="That")

L1.pack()
L2.pack()


I have tried setting

highlightthickness=4
highlightcolor="black"
highlightbackground="black"
borderwidth=4


inside the widget, but still the same result.

example pic tkinter

Is this even possible to do? Thank you!

Answer

If you want a border, the option is borderwidth. You can also choose the relief of the border ("flat", "raised", "sunken", "ridge", "solid", "groove"):

l1 = Label9root, text="This", borderwidth=2, relief="groove")

Note: "ridge" and "groove" require at least two pixels of width to render properly

examples of tkinter borders