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.
You can use grid, using the uniform
option. Put both halves in a "uniform group" by setting the uniform
option to the same value for both, and they will be the same size. To get the columns to grow/shrink with the window, give them equal weight.
Example:
frame1 = tk.Frame(parent, ...)
frame2 = tk.Frame(parent, ...)
frame1.grid(row=0, column=0, sticky="nsew")
frame2.grid(row=0, column=1, sticky="nsew")
parent.grid_columnconfigure(0, weight=1, uniform="group1")
parent.grid_columnconfigure(1, weight=1, uniform="group1")
parent.grid_rowconfigure(0, weight=1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With