How to add a border for a frame in Python Tkinter

How to add a border for a frame in Python Tkinter

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)

How to add a border for a frame in Python Tkinter

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.

Leave a Reply

Your email address will not be published. Required fields are marked *