BadCash BadCash - 5 months ago 26
Python Question

Make two Frames occupy 50% of the available width each?

How can I make two

Frame
s occupy 50% each of the available width of the window?

Right now I'm just letting the contents dictate the widths and using
pack(side=Tkinter.LEFT)
, and obviously that doesn't make them both equal width.

I tried using
grid()
instead, but then I couldn't get them to resize when I resize the window.

EDIT

Note that I want to be able to resize the window and the frames should resize with it to always be 50% of the width.

Answer

You can use grid, using the uniform option. Put both halves in a "uniform group" (same value for uniform option) and they will be the same size.

frame1 = tk.Frame(parent, ...)
frame2 = tk.Frame(parent, ...)

frame1.grid(row=0, column=0, sticky="nsew")
frame2.grid(row=0, column=1, sticky="nsew")

To get the columns to grow/shrink with the window, give them equal weight:

parent.grid_columnconfigure(0, weight=1, uniform="group1")
parent.grid_columnconfigure(1, weight=1, uniform="group1")
parent.grid_rowconfigure(0, weight=1)