如何在 Python 中更改按钮大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14247709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change button size in Python?
提问by John Forsgren
I am doing a simple project in school and I need to make six different buttons to click on. The buttons must have different sizes, but I can't find how do do it. I have made the button by using:
我在学校做一个简单的项目,我需要制作六个不同的按钮来点击。按钮必须有不同的尺寸,但我不知道怎么做。我使用以下方法制作了按钮:
def __init__(self, master):
super().__init__(master)
self.grid()
self.button1 = Button(self, text = "Send", command = self.response1)
self.button1.grid(row = 2, column = 0, sticky = W)
I imagine that something like:
我想像这样:
self.button1.size(height=100, width=100)
would work, but it doesn't and I cannot find how to do it anywhere.
会工作,但它不会,我无法在任何地方找到如何做到这一点。
I am using Python 3.3.
我正在使用 Python 3.3。
采纳答案by cdbitesky
Configuring a button (or any widget) in Tkinter is done by calling a configure method "config"
在 Tkinter 中配置按钮(或任何小部件)是通过调用配置方法 “config”来完成的
To change the size of a button called button1you simple call
要更改称为button1您的按钮的大小,请简单调用
button1.config( height = WHATEVER, width = WHATEVER2 )
If you know what size you want at initialization these options can be added to the constructor.
如果您知道初始化时需要什么大小,则可以将这些选项添加到构造函数中。
button1 = Button(self, text = "Send", command = self.response1, height = 100, width = 100)

