34

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.

2
  • 5
    You need to show more of the code than this (and fix the indentation). What toolkit are you using? wx? Tkinter? GTK? Commented Jan 9, 2013 at 22:35
  • 7
    By "the latest version of Python to this date" you mean 3.3? That's usually more helpful to say, especially since there are some old fogies out there who still consider 2.7 "the latest Python" because it's the latest 2.x… But, more importantly, if someone reads this question in 2015, he's not going to want to go look up the history of Python releases to figure out whether the answer is up to date… Commented Jan 9, 2013 at 22:43

2 Answers 2

64

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) 
Sign up to request clarification or add additional context in comments.

3 Comments

Is that the size in pixels?
@digitalHamster0 Yes it is in pixels.
@Person This is no longer the case I think. I am using tkinter version 8.6 in python3 and the button sizes are not in pixels. This answer provides a hack to work around this.
2

I've always used .place() for my tkinter widgets. place syntax

You can specify the size of it just by changing the keyword arguments!

Of course, you will have to call .place() again if you want to change it.

Works in python 3.8.2, if you're wondering.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.