使两个框架分别占据可用宽度的50%?

Mag*_*s W 6 python tkinter python-2.7

如何使两个Frames分别占据窗口可用宽度的50%?

现在,我只是让内容决定宽度并使用pack(side=Tkinter.LEFT),显然这并不能使它们都相等。

我尝试使用grid()代替,但是当我调整窗口大小时却无法调整它们的大小。

编辑

请注意,我希望能够调整窗口的大小,并且框架的大小应始终调整为宽度的50%。

Bry*_*ley 5

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)
Run Code Online (Sandbox Code Playgroud)