Below is my UI. I am trying to add a border for the frame.
But I am not getting any information on how to add a border. How can I do it?
Below is my UI. I am trying to add a border for the frame.
But I am not getting any information on how to add a border. How can I do it?
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.)
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)
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.
You can use relief and borderwidth like this.
from tkinter import *
root = Tk()
frame1 = Frame(root, width=400, height=660, bg="White", borderwidth=1, relief=RIDGE)
frame1.place(relx=0.7, y=80)
root.mainloop()
I have tried like:
frame_left = tk.Frame(window, width=100, height=360, bg="blue", borderwidth=1, relief=tk.RIDGE)
frame_left.pack(side=tk.LEFT, fill=tk.BOTH, expand=1)
frame_right = tk.Frame(window, highlightbackground="green", highlightthickness=10, width=100, height=100, bd=0)
frame_right.pack(side=tk.RIGHT, fill=tk.BOTH, expand=1)
See the link below to for what the output of the above code looks like: