在 Python 中更改 ttk 按钮高度 [英] Changing ttk Button Height in Python

查看:34
本文介绍了在 Python 中更改 ttk 按钮高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个愚蠢的问题,但是否可以手动更改 ttk 按钮的高度?

This seems like a silly question, but is it possible to change the height of a ttk button manually?

类似 button = tkinter.Button(frame, text='hi', width=20, height=20...) 之类的东西对于 tkinter 按钮来说效果很好.虽然我更喜欢使用 ttk 按钮,因为它在美学上看起来要好得多.

Something like button = tkinter.Button(frame, text='hi', width=20, height=20...) works just fine for a tkinter button. Though I'd prefer to use a ttk button since it looks much better aesthetically.

button = ttk.Button(frame, text='hi', width=20, height=20...) 不起作用,高度似乎不是一个有效的选项.我试过用 config 设置它或在样式中寻找要更改的元素,但没有任何运气.

button = ttk.Button(frame, text='hi', width=20, height=20...) does not work, height doesn't seem to be a valid option. I've tried setting it with config or looking for elements in the style to change and haven't had any luck.

有没有简单的解决方案?我正在使用 Python 2.7,Windows 作为记录.抱歉,这似乎是一个微不足道的问题,但我环顾四周,运气不佳.

Is there a simple solution to this? I'm using Python 2.7, Windows for the record. Sorry, this seems like kind of a trivial questions but I've looked around without much luck.

推荐答案

直接回答你的问题,不,你不能这样做.主题按钮的重点是提供统一的大小.

To directly answer your question, no, you can't do this. The whole point of themed buttons is to provide a uniform size.

话虽如此,仍有足够的空间进行开箱即用的思考.例如,您可以将按钮打包到框架中,关闭框架上的几何传播(因此框架的大小控制按钮的大小而不是反之亦然),然后将框架的大小设置为您想要的任何大小.

That being said, there's plenty of room for out-of-the-box thinking. For example, you can pack the button into a frame, turn geometry propagation off on the frame (so the size of the frame controls the size of the button rather than visa versa), then set the size of the frame to whatever you want.

或者,尝试在按钮上放置您想要的高度的透明图像,然后使用 compound 选项将标签覆盖在不可见图像上.

Or, try putting a transparent image on the button that is the height you desire, then use the compound option to overlay the label over the invisible image.

或者,创建一个使用填充来获得所需大小的自定义主题.

Or, create a custom theme that uses padding to get the size you want.

最后,您可以将按钮放在网格中,使其粘"到所有边,然后为该行设置最小高度.

Finally, you can put the button in a grid, have it "sticky" to all sides, then set a min-height for that row.

当然,如果您使用的是 OSX,那么所有的赌注都没有了——它真的想要使按钮具有特定大小.

Of course, if you are on OSX all bets are off -- it really wants to make buttons a specific size.

这篇关于在 Python 中更改 ttk 按钮高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆