0
我試圖讓我的頂框架在所有三個標籤之間具有相等的間距。我不想硬編碼「不可見」標籤的寬度來區分它們,因爲底部框架可能需要稍後擴大窗口大小。 現在,左邊的標籤被留下,然後有一個巨大的灰色區域看起來不屬於任何標籤,然後最後右側的中間和右側標籤被壓縮。有一個更好的方法嗎?使用多個框架時保持網格在蟒蛇間距
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()
感謝您的協助。上週我剛剛拿起tkinter,這一直在困擾着我。 – Twisted