我想让所有tkinter按钮的大小相同,无论文本如何。是否可以拉伸其他按钮以相互匹配或设置特定大小?因为我很难在文档中找到如何做到这一点。目前,按钮根据文本的大小进行拉伸。 Example of what I mean。是否有可能使它们大小相同?
当您使用几何管理器(pack
,place
或grid
)时,通常会执行此操作。
使用网格:
import tkinter as tk
root = tk.Tk()
for row, text in enumerate((
"Hello", "short", "All the buttons are not the same size",
"Options", "Test2", "ABC", "This button is so much larger")):
button = tk.Button(root, text=text)
button.grid(row=row, column=0, sticky="ew")
root.mainloop()
使用包:
import tkinter as tk
root = tk.Tk()
for text in (
"Hello", "short", "All the buttons are not the same size",
"Options", "Test2", "ABC", "This button is so much larger"):
button = tk.Button(root, text=text)
button.pack(side="top", fill="x")
root.mainloop()