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 info available in documentation: link
I request you to read the documentation thoroughly, and 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 used to change the color of the widget in focus
-> highlightthickness 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.