Search code examples
pythontkinter

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

Solution

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