Home > OS >  I can't place frames the way i want in tkinter
I can't place frames the way i want in tkinter

Time:08-30

Good afternoon! Right to the heart of the matter: I have a window, it has a tab, and in it I want to place three main frames. One on the left, one on the right and one on the bottom. It is impossible to arrange the first two at the same level horizontally. Screenshots of how it looks now, and how I would like to see it, are attached. Here is a part of the code:

my_notebook.tab(current_tab, text=gang.name)
frame_left = Frame(current_tab, borderwidth=2, relief=GROOVE)  # THIS IS TOP LEFT FRAME
frame_left.pack(anchor=NW)
frame_right = Frame(current_tab, borderwidth=2, relief=GROOVE)  # THIS IS TOP RIGHT FRAME
frame_right.pack(anchor=NE)
f11 = LabelFrame(current_tab, borderwidth=2, pady=5, text="Founders", font=('arial', 14), relief=GROOVE) #  THIS IS BOTTOM FRAME
f11.pack(anchor=S, fill=BOTH)

enter image description here

Changing the padx, pady parameter of the .grid() to:

L_l.grid(row=1, column=1,  padx=50, pady=20)
L_r.grid(row=1, column=2,  padx=50, pady=20)
L_b.grid(row=2, column=1, columnspan=2, pady=30)

gives:

enter image description here

adding the code for appropriate values impacting the size of rows/columns respectively to others:

root.grid_rowconfigure(   1, weight=1)
root.grid_columnconfigure(1, weight=1)
root.grid_columnconfigure(2, weight=1)
# other possible parameter here is minsize= expressed in pixels
# to prevent too small sizes when shrinking tkinter window

will result in better response of the layout to resizing the tkinter window as shown in the picture below:

enter image description here

  • Related