'Trying to extend this frame to the bottom but can't get it to work
I have 1 window with 2 frames inside, and i am trying to make it that the left frame (frame_side) is filled to the bottom of the screen even if you expand it. But since i don't use .pack() I tried using .rowconfigure() but it still doesn't work.
Blue area needs to be extended
window.geometry('950x650')
window.resizable(height=None, width=None)
frame_side = Frame(window, borderwidth=5, bg='gray')
frame_side.grid(column=0, row=0, rowspan=100)
frame_main = Frame(window)
frame_main.grid(column=1, row=0, rowspan=100)
lbl = Label(frame_main, text="Password Vault")
lbl.grid(column=1, row=0)
img1o = Image.open("images/plus.png")
resize_img1 = img1o.resize((24, 24))
img1 = ImageTk.PhotoImage(resize_img1)
img2o = Image.open("images/gear_hollow.png")
resize_img2 = img2o.resize((24, 24))
img2 = ImageTk.PhotoImage(resize_img2)
img3o = Image.open("images/add.png")
resize_img3 = img3o.resize((24, 24))
img3 = ImageTk.PhotoImage(resize_img3)
btn = Button(frame_side, image=img1, command=addEntry)
btn.image = img1
btn.grid(column=0, row=3)
btn1 = Button(frame_side, image=img2, command=openSettings)
btn1.image = img2
btn1.grid(column=0, row=0)
btn2 = Button(frame_side, image=img3, command=openUser)
btn2.image = img3
btn2.grid(column=0, row=1)
fill = Label(frame_side, bg='gray')
fill.grid(column=0, row=2)
fill1 = Label(frame_side, bg='gray')
fill1.grid(column=0, row=4, sticky='ns')
frame_side.grid_rowconfigure(0, weight=1) # tried to configure the frame
fill1.grid_rowconfigure(0, weight=1) # and the label itself
Solution 1:[1]
I have found the solution:
- I first used rowconfigure with weight 1 on row 0 because otherwise the other rowconfigure wont work.
- Then i used columnconfigure weight 1 for column 0, and columnconfigure weight 1000 for column 1, so the column will stay thin even on full screen.
- And then I needed to do columnconfigure weight 1 column 1 inside the frame_side and rowconfigure weight 1000 on the last row for the same reason in the main window.
Full code:
window.geometry('950x650')
window.resizable(height=None, width=None)
window.rowconfigure(0, weight=1)
window.columnconfigure(0, weight=1)
window.columnconfigure(1, weight=1000)
frame_side = Frame(window, borderwidth=5, bg='gray')
frame_side.grid(column=0, row=0, sticky='NSEW')
frame_side.rowconfigure(8, weight=1000)
frame_side.columnconfigure(0, weight=1)
Don't forget to put sticky='NSEW'
in the row and the frame
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Charles Duffy |