Tkinter frame not showing border

I am using the Frame widget in tkinter and have used highlightthickness and highlightcolor attributes. I have then added my label into the frame, however when run, the label appears on the window however the frame is not? The frame must be there or the label wouldn’t appear so im not sure what the issue could be?

import time
import threading
import tkinter as tk
from tkinter import ttk, PhotoImage

def main():
    main_win = tk.Tk()
    main_win.title("Functional Pomodoro Timer")
    main_win.minsize(400, 200)
    frame1 = tk.Frame(main_win, highlightthickness=20, highlightcolor="black",
                      relief=tk.RIDGE), y=0, relwidth=0.5, relheight=0.5)
    time_label = tk.Label(frame1, text="00:00", font=("Arial", 24)), relheight=0.5)

if __name__ == "__main__":

Tried using frame with label in it, the label has appeared on the window, however when i use border attributes on the frame, it doesn’t work. I have also used .place() however none of the arguments seem to be noticed.

>Solution :

The highlight ring only shows up when the frame has the keyboard focus, which it rarely does. Unless the frame has focus, the ring will not show even when you set the highlightthickness attribute.

You can see the highlight ring by adding frame1.focus_set() to your code. However, the purpose of the highlight ring isn’t to be a border. It is an indicator of focus, so that’s not a proper solution.

If you want a border, set the borderwidth and relief attributes.

frame1 = tk.Frame(main_win, borderwidth=2, relief=tk.RIDGE)

screenshot showing the border

Leave a Reply