How to put border for Frame in Python Tkinter
41,031
Solution 1
The requested feature is not called a border in Tkinter. It is called a highlight.
To get the above request, set highlightbackground="black"
and highlightthickness=1
.
(The border is the empty space reserved around the frame) Additional information is available in documentation.)
Solution 2
In the documentation, look at the styles you can apply to a frame using Tkinter: Tkinter Frame Widget
Here is how you do this:
import tkinter as tk
#tk.Frame(master, **config-options)
my_frame = tk.Frame(parent_widget, borderwidth = 1)
Solution 3
from tkinter import *
root = Tk()
frame1 = Frame(root, highlightbackground="blue", highlightthickness=1,width=600, height=100, bd= 0)
frame1.pack()
root.mainloop()
-
change the options accordingly
-
highlightbackground is used to change the color of the widget in focus
-
highlightthickness is used to specify the thickness of the border around the widget in focus.
Author by
sreevathsabr
Updated on September 18, 2021Comments
-
sreevathsabr over 2 years
Below is My UI , I am trying to Put Border for the frame. But i am Not getting any information on How to Put border . Please help me over it .
-
Harlin over 3 yearsThe doc link (at the effbot site) appears to be not viable: "effbot.org is taking a break. We’ll be back, in some form or another." These two options could use better explanation -- i.e. which widget are these options added? Using a frame I get _tkinter.TclError: unknown option "-highlightbackground". I'm requesting since this "answer" appears to be the most upvoted for this question.
-
Mi-krater over 2 yearsI have to agree with Harlin, this doesn't appear to work for me at all. I think this answer needs updating
-
Peter Mortensen about 2 yearsDo they have a name in Python? Named parameters? Perhaps add (non-naked) specific links to documentation for those two? (But without "Edit:", "Update:", or similar - the answer should appear as if it was written today.)