简体   繁体   English

如何使用Python Tkinter修复与按钮文本无关的大小?

[英]How with Python Tkinter do I fix the size irrelevant of text of buttons?

I have the following example code: 我有以下示例代码:

    # Button grid modifications
    self.connectButton.grid(row=5, columnspan=2,
        sticky=N + S + E + W)
    self.SelectButton.grid(row=6, rowspan=2, column=0,
        sticky=N + S + E + W)
    self.configButton.grid(row=6, rowspan=2, column=1,
        sticky=N + S + E + W)
    self.ImageButton.grid(row=7, columnspan=2,
        sticky=N + S + E + W)
    self.ImageButton2.grid(row=8, columnspan=2,
        sticky=N + S + E + W)

This displays a 2 column button over two 1 column buttons over a few more 2 column buttons. 这将在两个1列按钮上方的两个1列按钮上方显示两个2列按钮。 Depending on the text I use, it changes drastically and unproportionally both vertically and horizontally. 根据我使用的文字,它在垂直和水平方向上都会发生急剧和不成比例的变化。 I've tried using the weight=1 but that didn't seem to work either. 我尝试使用weight = 1,但这似乎也不起作用。 I know there has to be a simple solution. 我知道必须有一个简单的解决方案。 How can I get it to be the same regardless of text / platform? 无论文本/平台如何,我如何使它相同? This is supposed to be portable. 这应该是便携式的。

Thanks for any help. 谢谢你的帮助。

您可以使用具有特定width config来保持按钮固定:

self.connectButton.config(width=some_width_as_int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM