Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 

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.

like image 675
John Forsgren Avatar asked Jan 09 '13 22:01

John Forsgren


People also ask

Can you change button shape Tkinter?

Tkinter Button ShapeShapes can be rectangular, oval, circle, etc. You cannot create a rounded button directly from the widget. to do so you need a rounded image. And then reduce the border width to 0.

How do I change the size of my TTK button?

We can change the height of the ttk button by using the grid(options) method. This method contains various attributes and properties with some different options. If we want to resize the ttk button, we can specify the value of internal padding such as ipadx and ipady.

Can you make buttons in Python?

The Button widget is used to add buttons in a Python application. These buttons can display text or images that convey the purpose of the buttons. You can attach a function or a method to a button which is called automatically when you click the button.


Video Answer


1 Answers

Configuring a button (or any widget) in Tkinter is done by calling a configure method "config"

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)  
like image 149
cdbitesky Avatar answered Oct 16 '22 11:10

cdbitesky