How to add a border for a frame in Python Tkinter

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?

Border as in the image

0

5 Answers

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.)

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)
0
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.

0

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()
1

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:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like