Python/Tkinter 网格粘性未填充垂直空间

编程入门 行业动态 更新时间:2024-10-28 18:26:58
本文介绍了Python/Tkinter 网格粘性未填充垂直空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 05:58:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390074.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:粘性   网格   空间   Python   Tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!