问题描述
限时送ChatGPT账号..我正在尝试创建一个按钮网格.这些按钮内的文本会发生变化,所以我希望按钮变大 - 填充每个网格元素的边框.下面的代码是一个简化版本,它说明了这个问题.按钮大多填充水平空间,但不填充垂直空间(除非添加多行文本作为按钮标签).
I'm trying to create a grid of buttons. The text within these buttons will change, so I want to buttons to be large - filling the borders of each grid element. The code below is a simplified version which illustrates the issue. The buttons mostly fill the horizontal space, but do not fill the vertical space (unless multiple lines of text are added as a button label).
from Tkinter import *
root = Tk()
buttons = {}
for y in range(3):
root.rowconfigure(y, minsize=60)
for x in range(3):
root.columnconfigure(x, minsize=60)
for y in range(3):
n = 3 * x + y
buttons[n] = Button(root).grid(column=x, row=y, sticky=W + E + N + S)
root.mainloop()
这对我来说是这样的:
推荐答案
OSX 上的按钮确实希望看起来像 OSX 按钮,并且不会以您想要的方式展开.这是使用本机小部件的陷阱之一.
Buttons on OSX really want to look like OSX buttons, and won't expand the way you want. This is one of the pitfalls of using native widgets.
这篇关于Python/Tkinter 网格粘性未填充垂直空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论