我试图让我的顶部框架在所有三个标签之间具有相等的间距。我不想硬编码“不可见”标签的宽度来分隔它们,因为底部框架可能需要稍后扩展窗口大小。现在,左边的标签在左边,然后有一个巨大的灰色区域,看起来不属于任何标签,最后中间和右边的标签在右侧被挤压。有一个更好的方法吗?
from tkinter import *
from tkinter import ttk
#Build buttons
def create_buttons():
for y in range(6):
for x in range(6):
ttk.Button(bot_frame, width = 5, text = str(x) + "," + str(y)).grid(column = x, row = y, sticky = W)
root = Tk()
#top frame
top_frame = ttk.Frame(root, padding = "4 4 4 4")
top_frame.grid(column = 0, row = 0, sticky = (N, E, S, W))
top_frame.columnconfigure(0, weight = 1)
top_frame.rowconfigure(0, weight = 1)
top_frame['borderwidth'] = 2
top_frame['relief'] = 'sunken'
#bottom frame
bot_frame = ttk.Frame(root, padding = "4 4 4 4")
bot_frame.grid(column = 0, row = 2, sticky = (N, E, S, W))
bot_frame.columnconfigure(0, weight = 1)
bot_frame.rowconfigure(0, weight = 1)
bot_frame['borderwidth'] = 2
bot_frame['relief'] = 'sunken'
#Top labels
left_lbl = ttk.Label(top_frame, background = 'black', foreground = 'green', width = 5, text = "left").grid(column = 0, row = 0, sticky = (N, W))
center_lbl = ttk.Label(top_frame, background = 'red', width = 6, text = 'center').grid(column = 1, row = 0, sticky = (N, E, S, W))
right_lbl = ttk.Label(top_frame, background = 'black', foreground = 'green', width = 5, text = "right").grid(column = 2, row = 0, sticky = (N, E))
create_buttons()
root.mainloop()