Python Tkinter How to remove the border around a Frame?

Mike - SMT picture Mike - SMT · May 9, 2017 · Viewed 8.7k times · Source

I have a program with several frames. Everything works well however I cannot figure out why the border around one of the frames exist.

I have tried a few things.

Here is how my frame is created:

kwListFrame = Frame(root)
kwListFrame.grid(row = 1, column = 0, rowspan = 1, columnspan = 1, sticky = N+S+E+W)
kwListFrame.columnconfigure(0, weight=1)
kwBGimage = Label(kwListFrame, image= baseBGimage)
kwBGimage.image = baseBGimage
kwBGimage.place(x = 0, y = 0)
kwBGimage.config(image = baseBGimage)

I have tried to change:

kwListFrame = Frame(root)

To:

kwListFrame = Frame(root, highlightthickness=0)
#or
kwListFrame = Frame(root, padx=0, pady=0)
#or
kwListFrame = Frame(root, bd=0)

And after that didnt work I tried:

kwListFrame = Frame(root, highlightbackground= "some color that matches frame")

I even tried to set the relief to flat even thought I know its default value is flat.

As I have found several references to removing the border on canvas, I have not found anything related to Frames directly. So I may be using the highlightthickness and highlightbackground wrong but it did not throw an error so it seams like it should do the trick.

Here is an image of the way the frame displays a thin border at the top.

enter image description here

I am not sure why the problem exist. Is it because I am using an image as the background?

I did not want to post all my code here because it would be to much but if you want to see the full code my program is on Github

Answer

Bryan Oakley picture Bryan Oakley · May 9, 2017

The first step is to set both the borderwidth and highlightthickness to zero. A frame has two border-like objects: the actual border and a "highlight ring". The latter is for showing that a frame has focus.

Once you do that, the frame will not have a border. If there's still some sort of border-like ring around the widget it is likely due to padding applied to the geometry manager, and what you are seeing is the color from the parent window.

In your specific case, since you are putting a label in the frame you need to turn the border of the label off, too. Most likely you are seeing the border of the label rather than the border of the frame.

I can't be any more specific since you didn't provide a minimal but otherwise fully working example that illustrates the problem.