Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.resizable(True,True)
    main_win.minsize(400, 200)
    main_win.geometry("800x400")
    frame1 = tk.Frame(main_win, highlightthickness=20, highlightcolor="black",
                      relief=tk.RIDGE)
    frame1.place(x=0, y=0, relwidth=0.5, relheight=0.5)
    time_label = tk.Label(frame1, text="00:00", font=("Arial", 24))
    time_label.place(relwidth=0.5, relheight=0.5)
    main_win.mainloop()

if __name__ == "__main__":
    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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading