Irena Jodeikiene Irena Jodeikiene - 1 year ago 87
Python Question

How make tkinter frame go behind other

I'm trying to make ( = Separator) go behind that only line would be in center, because i need to seperate 2 frames, but when I try on small screen those 2 frames are covered by seperator or at least make center frame backgroud trasperent, If you need full code

self.right= Frame(, bg="black")
self.right.grid(column=2, row = 0, pady=5,padx=10, sticky=N)

self.probar= Frame(, bg= "black")
self.probar.grid(column=0 ,columnspan= 2, row = 2, sticky= E) = Separator(, orient="vertical"), row=0, sticky="ns")

sty = Style(
sty.configure("TSeparator", background="#00CC00")

self.botFrame = Frame(, bg="black")
self.botFrame.grid(column=2, row = 2, pady=1, sticky= SE)

self.colnr = 0
self.rownrleft = 0
self.rownrright = 0

self.titlelbl= Label(self.right, text="Service Status:",bg="black",
fg="#00CC00",font=("Helvetica", 24))
self.titlelbl2= Label(self.left, text="GW Status:",bg="black",
fg="#00CC00",font=("Helvetica", 24))
self.titlelbl.grid(column=0, row = 0,sticky=N)
self.titlelbl2.grid(column=0, row = 0,sticky=N)

self.progress = ttk.Progressbar(self.probar,orient ="horizontal",
length = 410, mode ="determinate")
self.progress.grid(column=0, row = 0,pady= (20,0))

self.string = StringVar()
self.timecount = StringVar()

self.titlelbl3= Label(self.probar, textvariable= self.string ,
bg="black", fg="#00CC00",font=("Helvetica", 24))
self.titlelbl3.grid(column=0, row = 1)


So basicly what was wrong is that progress bar was expanding collumn. But theres new problem how place progressbar in middle of bottom that it wouldnt expand col 1

Answer Source

I think your problem is due to the width of column 1 which is determined by the largest widget (I don't think it's the separator here, but the progress bar). I suggest you to put all row 0 widget in one frame so that they won't be impacted by the other wigets width:

from tkinter import Tk, Frame
from tkinter import ttk

root = Tk()
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)

# create a top frame that will contain left, center and right
# and will spread other the 3 columns so that the width of column 1
# does not decrease the width of the left and right frames
top = Frame(root)
top.grid(row=0, columnspan=3, sticky="nswe")
top.columnconfigure(0, weight=1)
top.rowconfigure(0, weight=1)

left= Frame(top, bg="blue", width=200, height=100)
left.grid(column=0, row = 0, pady=5 ,padx=10, sticky="n")

center = ttk.Separator(top, orient="vertical")
center.grid(column=1, row=0, sticky="ns")

sty = ttk.Style(center)
sty.configure("TSeparator", background="#00CC00")

right= Frame(top, bg="blue", width=200, height=100)
right.grid(column=2, row = 0, pady=5,padx=10, sticky="n")

probar= Frame(root, bg= "black")
probar.grid(column=1, row = 1, sticky= "s")

botFrame = Frame(root, bg="black", width=100, height=50)
botFrame.grid(column=2, row = 1, pady=5, sticky="se")

progress = ttk.Progressbar(probar,orient ="horizontal",
                           length = 410, mode ="determinate")
progress.grid(column=0, row = 0,pady= (20,0))