Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I make two Frames 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.

like image 707
Magnus Avatar asked Jul 03 '16 14:07

Magnus


1 Answers

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)
like image 132
Bryan Oakley Avatar answered Sep 19 '22 13:09

Bryan Oakley