Tkinter对齐多个帧

时间:2018-05-30 10:25:45

标签: python tkinter

我在使用ttk模块放置三个帧时遇到问题。我需要让它们具有相同的尺寸。左边的一个放置正确,但右边的那个应该匹配第一个的大小。

我的代码是:

from tkinter import *
from tkinter import ttk

master = Tk()

frame_labels = ttk.Frame(master, width=500, height=500, relief=SUNKEN)
frame_labels.grid(row=1, column=1, padx=10, pady=10, sticky='n')

frame_log = ttk.Frame(master, width=500, height=300, relief=SUNKEN)
frame_log.grid(row=1, column=3, padx=0, pady=10, sticky='n')

credits_frame = ttk.Frame(master, width=500, height=200, relief=SUNKEN)
credits_frame.grid(row=2, column=3, padx=0, pady=10, sticky='n')

master.mainloop()

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

第一帧(左)需要跨越两行。他们都需要更多的“粘性”。

from tkinter import *
from tkinter import ttk

master = Tk()

frame_labels = ttk.Frame(master, width=500, height=500, relief=SUNKEN)
frame_labels.grid(row=1, column=1, padx=10, pady=10, sticky='news', rowspan=2)

frame_log = ttk.Frame(master, width=500, height=300, relief=SUNKEN, style='My.TFrame')
frame_log.grid(row=1, column=3, padx=0, pady=10, sticky='news')

credits_frame = ttk.Frame(master, width=500, height=200, relief=SUNKEN)
credits_frame.grid(row=2, column=3, padx=0, pady=10, sticky='news')

master.mainloop()