Overdrivr
Overdrivr

Reputation: 6576

tkinter frame border not displaying

I wish to display the border of a frame holding several widgets, but despite setting a width to the border and SUNKEN value to relief, no border shows up

It works perfectly fine on an empty frame so I'm guessing it does not work with a frame with children, is this correct ?

How can I do it anyway ? Or at least introduce separation between two areas of my interface

Test code :

import tkinter as Tk

class Application(Tk.Frame):

    def __init__(self, **kwargs):
        #Create window
        self.root = Tk.Tk()

        #Init master frame
        Tk.Frame.__init__(self,self.root,width=640, height=480)
        self.grid()

        #Frame
        self.frame_com_ports = COM_Frame(self,borderwidth=5,relief=Tk.GROOVE)
        self.frame_com_ports.grid(column=0,row=0,sticky='EW')

        #Some other frames here...

class COM_Frame(Tk.Frame):
    def __init__(self,parent, **kwargs):
        Tk.Frame.__init__(self,parent)

        #Widgets
        self.txt_ports = Tk.Label(self,text="WIDGET1")
        self.txt_ports.grid(column=0,row=0,sticky='EW',pady=3,padx=3)

        self.txt_ports = Tk.Label(self,text="WIDGET2")
        self.txt_ports.grid(column=0,row=1,sticky='EW',pady=3,padx=3)

if __name__ == "__main__":
    app = Application()
    app.mainloop()

Upvotes: 4

Views: 13716

Answers (4)

lacy025
lacy025

Reputation: 1

show_table = tk.Frame(window, width=960, highlightbackground="yellow", highlightthickness=5, height=250, bg="red")
show_table.place(x=5, y=5)

Upvotes: 0

David Cely
David Cely

Reputation: 121

my_frame.config(bd=1, relief=tkinter.SOLID)

Upvotes: 2

Bryan Oakley
Bryan Oakley

Reputation: 385890

You are passing borderwidth and relief to the COM_Frame constructor, but you aren't using those values when calling the Frame constructor. You need to change this:

Tk.Frame.__init__(self,parent)

... to this:

Tk.Frame.__init__(self,parent, **kwargs)

Upvotes: 5

eivl
eivl

Reputation: 148

The default relief for a frame is tk.FLAT, which means the frame will blend in with its surroundings. To put a border around a frame, set its borderwidth to a positive value and set its relief to one of the standard relief types.

Upvotes: 5

Related Questions