【发布时间】:2020-10-22 10:14:26
【问题描述】:
我一直在尝试学习如何使用 python 和 Tkinter。 当我有多列大小不同的按钮时,它们不会像我期望的那样根据我制作的大小对齐。
它的样子:
如您所见,高度设置为 100 的按钮仅使用与高度为 10 的 6 个按钮相同的空间,而不是像预期的那样占据整个高度。
预期结果:
有什么方法可以按预期对齐按钮,而无需手动尝试确定点亮它们所需的大小?
代码:
import tkinter as tk
import tkinter.font as tkFont
root = tk.Tk()
pixelVirtual = tk.PhotoImage(width=1, height=1)
large = tk.Button(root,
text='Height=100',
image=pixelVirtual,
width=100,
height=100,
compound='c')
for i in range(10):
small = tk.Button(root,
text='Height=10',
image=pixelVirtual,
width=100,
height=10,
compound='c')
small.grid(row=i, column= 1)
large.grid(row=0, rowspan=10, column=0)
root.mainloop()
【问题讨论】:
标签: python-3.x tkinter layout alignment