pythontkinterttk

ttk Frames not filling properly


I am making a python application that uses 4 ttk Frames within its main window. The first two frames should expand both vertically and horizontally to fill available space. Frames 3 and 4 should only expand horizontally and be a fixed height vertically. This is my code so far (minimum working example):

import tkinter as tk
from tkinter import ttk

tk_root = tk.Tk()
tk_root.geometry('500x500')

frame_1 = ttk.Frame(tk_root, padding=10, borderwidth=3, relief=tk.GROOVE)
frame_2 = ttk.Frame(tk_root, padding=10, borderwidth=3, relief=tk.GROOVE)
frame_3 = ttk.Frame(tk_root, padding=10, borderwidth=3, relief=tk.GROOVE, height=50)
frame_4 = ttk.Frame(tk_root, padding=10, borderwidth=3, relief=tk.GROOVE, height=50)

frame_1.pack(fill=tk.BOTH, expand=True)
frame_2.pack(fill=tk.BOTH, expand=True)
frame_3.pack(fill=tk.X, expand=True)
frame_4.pack(fill=tk.X, expand=True)

tk_root.mainloop()

When i run this the first two frames only expand to 50% of the window height and empty space is left around frames 3 and 4 (screenshot). I would like to have frames 3 and 4 be a constant height while frames 1 and 2 expand to fill all available space above frames 3 and 4.

Frames 1&2 filling the top half of the window, frames 3 and for with vertical space above and below them.


Solution

  • acw1668 gave the answer in a comment:

    Remove expand=True for frame 3 and 4.

    That did the trick.