Pack 4 frames inside the window (tkinter)

Viewed 52

Good day everyone! I need to place four frames inside the window as shown in the picture, and using the .pack() method. Now I have 3 frames placed in the window (picture before), and I want to add another one by moving frame f11 to the right. I also attach a picture with how it should look as a result (picture after).

Current part of code:

f11 = LabelFrame(current_tab, borderwidth=2, pady=5, relief=GROOVE, labelwidget=lbl_frm_wdgt_founder)
f11.pack(side=BOTTOM, fill=BOTH)

frame_left = Frame(current_tab, borderwidth=0, relief=GROOVE)
frame_left.pack(side=LEFT, fill=BOTH)

frame_right = LabelFrame(current_tab, labelwidget=lbl_frm_wdgt_arb, borderwidth=2, relief=GROOVE)
frame_right.pack(side=RIGHT, fill=BOTH)

frame_bottom_left = Frame(current_tab, borderwidth=2, relief=GROOVE)
# frame_bottom_left.pack(???)
1 Answers

If you don't want to / can't use grid(), you can use tk.Frame() widgets as generic containers

import tkinter as tk  # don't use star imports!
from tkinter import ttk


top_container = tk.Frame(current_tab)
top_container.pack(expand=True, fill=tk.X, side=tk.TOP)
# top container children
frame_left = Frame(
    top_container,
    borderwidth=0,
    relief=tk.GROOVE
)
frame_left.pack(side=tk.LEFT, fill=tk.BOTH)

frame_right = LabelFrame(
    top_container,
    labelwidget=lbl_frm_wdgt_arb,
    borderwidth=2,
    relief=tk.GROOVE
)
frame_right.pack(side=tk.RIGHT, fill=tk.BOTH)

bottom_container = tk.Frame(current_tab)
bottom_container.pack(expand=True, fill=tk.X, side=tk.BOTTOM)
# bottom container children
frame_bottom_left = tk.Frame(
    bottom_container,
    borderwidth=2,
    relief=tk.GROOVE
)
frame_bottom_left.pack(side=tk.LEFT, fill=tk.BOTH)

f11 = ttk.LabelFrame(
    bottom_container,
    borderwidth=2,
    pady=5,
    relief=tk.GROOVE,
    labelwidget=lbl_frm_wdgt_founder
)
f11.pack(side=tk.RIGHT, fill=tk.BOTH)

Since the container frames are packed separately, you can use one on top and another on the bottom

P.S.: Try to avoid * star imports - make sure to properly namespace all constants e.g. tk.LEFT and classes e.g. ttk.LabelFrame

Related