BadCash BadCash - 1 year ago 95
Python Question

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

How can I make two

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

Right now I'm just letting the contents dictate the widths and using
, and obviously that doesn't make them both equal width.

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


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 Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download