使Tkinter按钮具有相同的大小 [英] Make tkinter buttons the same size
本文介绍了使Tkinter按钮具有相同的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使所有tkinter按钮的大小相同,而与文本无关.是否可以拉伸其他按钮以相互匹配或设置特定的大小?由于我在文档中很难找到解决方法.当前,按钮会根据文本的大小进行拉伸.我的意思示例.是否可以使它们大小相同?
I want to make all the tkinter buttons the same size regardless of text. Is it possible to stretch other buttons to match each other or set a specific size? As I am having difficulty finding how to do so in the documentation. Currently the buttons stretch based on the size of the text. Example of what I mean. Is it possible to make them all the same size?
推荐答案
使用几何管理器( pack
, place
或网格
).
You would typically do this when you use a geometry manager (pack
, place
, or 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()
这篇关于使Tkinter按钮具有相同的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文