如何在 Python 中更改按钮大小? [英] How do I change button size in Python?
问题描述
我在学校做一个简单的项目,我需要制作六个不同的按钮才能点击.按钮必须有不同的尺寸,但我不知道怎么做.我使用以下方法制作了按钮:
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)
我想像这样:
self.button1.size(height=100, width=100)
可以,但不行,而且我在任何地方都找不到方法.
would work, but it doesn't and I cannot find how to do it anywhere.
我使用的是 Python 3.3.
I am using Python 3.3.
推荐答案
在 Tkinter 中配置按钮(或任何小部件)是通过调用配置方法完成的"配置"
Configuring a button (or any widget) in Tkinter is done by calling a configure method "config"
要更改名为 button1
的按钮的大小,您只需调用
To change the size of a button called button1
you simple call
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)
这篇关于如何在 Python 中更改按钮大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!