Regarding your initial question: the button does appear physically. The problem is, since it is so large, it is hard to distinguish from the rest of the window.

Now, you said that your ultimate goal is to change the size of a button. If so, then you are on the right track: you use the height and width options for this.

However, I would recommend that you make a few changes to your code:

  1. Don't make the button so huge. Even on a very big monitor, having a button be that size is way overkill.
  2. Don't make the window so huge. Nobody wants an application that takes up the entire screen.
  3. Use .grid instead of .place. Doing so will make it easier for you to place widgets where you want them.
  4. Set the height and width options when you make the button, not after it.
  5. There is no need to import sys here. Only import what you need.
  6. Don't import like this: from tkinter import *. Doing so dumps a whole bunch of names in the global namespace that can easily be overwritten.

Here is my version of your script:

import tkinter as tk

def mmWindow():
    mmWindow = tk.Tk()
    mmWindow.geometry('600x600')

mWindow = tk.Tk()
# You can set any size you want
mWindow.geometry('500x500+0+0')
mWindow.title('DMX512 Controller')

wtitle = tk.Label(mWindow, text="Pi DMX", fg='blue')
wtitle.grid(row=0, column=1)

# You can set any height and width you want
mmbutton = tk.Button(mWindow, height=5, width=20, text="Main Menu", command=mmWindow)
mmbutton.grid(row=1, column=1)

mWindow.mainloop()
Answer from user2555451 on Stack Overflow
Top answer
1 of 3
6

Regarding your initial question: the button does appear physically. The problem is, since it is so large, it is hard to distinguish from the rest of the window.

Now, you said that your ultimate goal is to change the size of a button. If so, then you are on the right track: you use the height and width options for this.

However, I would recommend that you make a few changes to your code:

  1. Don't make the button so huge. Even on a very big monitor, having a button be that size is way overkill.
  2. Don't make the window so huge. Nobody wants an application that takes up the entire screen.
  3. Use .grid instead of .place. Doing so will make it easier for you to place widgets where you want them.
  4. Set the height and width options when you make the button, not after it.
  5. There is no need to import sys here. Only import what you need.
  6. Don't import like this: from tkinter import *. Doing so dumps a whole bunch of names in the global namespace that can easily be overwritten.

Here is my version of your script:

import tkinter as tk

def mmWindow():
    mmWindow = tk.Tk()
    mmWindow.geometry('600x600')

mWindow = tk.Tk()
# You can set any size you want
mWindow.geometry('500x500+0+0')
mWindow.title('DMX512 Controller')

wtitle = tk.Label(mWindow, text="Pi DMX", fg='blue')
wtitle.grid(row=0, column=1)

# You can set any height and width you want
mmbutton = tk.Button(mWindow, height=5, width=20, text="Main Menu", command=mmWindow)
mmbutton.grid(row=1, column=1)

mWindow.mainloop()
2 of 3
1
import sys
from tkinter import *

def update_window_size():
    mmWindow.geometry('600x600')

mmWindow  = Tk()
mmWindow .geometry('1920x1080+0+0')
mmWindow .title('DMX512 Controller')

wtitle = Label(mmWindow, text="Pi DMX", fg='blue')
wtitle.place(relx=0.33, rely=0.0925925)

mmbutton = Button(mmWindow, text="Main Menu", command=update_window_size)
mmbutton.place(relw=0.104167, relh=0.185185, relx=0.104167, rely=0.185185)

mmWindow.mainloop()

I know this is late, but just want to add my method of how to solve the issue of how to make the button size change. I believe using place with relw and relh will be a better way to go. relw and relh & relx and rely will be fraction of the height and width of the parent widget. Therefore you do not need to worry about adjusting the size of both the wtitle and mmbutton.

If you want to change it's width and height from place then just put the code below on button command.

def update_button_size():
    mmbutton.place(width=20, height=20)

mmbutton = Button(mmWindow, text="Main Menu", command=update_button_size)
mmbutton.place(width=400, height=400, relx=0.104167, rely=0.185185)

If you want to change it's width and height from config then use code below.

def update_button_size():
    mmbutton.config(width=20, height=20)

mmbutton = Button(mmWindow, text="Main Menu", command=update_button_size)
mmbutton.place(relx=0.104167, rely=0.185185)
mmbutton.config(width=400, height=400)

From my understanding config width and height is different from place width and height.

🌐
Delft Stack
delftstack.com › home › howto › python tkinter › how to change the tkinter button size
How to Change the Tkinter Button Size | Delft Stack
February 5, 2025 - The reason why Tkinter uses text units for measurement of width and height but not inches or pixels is that text unit ensures the consistent behavior of Tkinter across different platforms. import tkinter as tk import tkinter.font as tkFont app = tk.Tk() app.geometry("400x200") buttonExample1 = tk.Button(app, text="Button 1", width=10, height=10) buttonExample2 = tk.Button(app, text="Button 2", width=10, height=10) buttonExample1.pack(side=tk.LEFT) buttonExample2.pack(side=tk.RIGHT) app.mainloop()
Discussions

python - How to adjust Tkinter button height? - Stack Overflow
I'm sorry that my question might sounds stupid but I have read some wiki as well as questions posted on Stack Overflow, however, when I tried to adjust the button height, it seems only the frame size More on stackoverflow.com
🌐 stackoverflow.com
September 21, 2014
python - Resize a button less than 1 pixel like (0.5) - Stack Overflow
I want to resize my buttons height & weight less than 1. Is that possible? More on stackoverflow.com
🌐 stackoverflow.com
May 13, 2018
python - Is it possible to reduce a button size in tkinter? - Stack Overflow
I'm working on a little text editor and currently making the buttons, on the picture bellow the 'B' button for bold. I would like to reduce his size in order to make him fit his true size, like a s... More on stackoverflow.com
🌐 stackoverflow.com
How do I make the buttons be square in Tkinter?
By default, width and height of Tkinter buttons is set in text units. A text unit is either the width or the height of the character 0 (zero) in the font you're currently using. So you can see the problem. 10 text units high is more distance than 10 text units wide, and the difference depends on which font you're using. You can set the size of the button in pixels using a bit of a trick. If you add an image to the button, the size values will be interpreted as pixels. So, you can just create a blank 1x1 image and add it to the button. You also need to set the button's "compound" parameter so that it shows both the text and image. Here's a sample: import tkinter as tk root = tk.Tkinter() i = tk.PhotoImage(width=1, height=1) # this button will be tall and rectangular, because it's using text units b1 = tk.Button(root, text='text units', width=20, height=20) b1.pack # this button will be square, because it's using pixels b2 = tk.Button(root, text='Pixels', image=i, compound='c', width=100, height=100) b2.pack root.mainloop() More on reddit.com
🌐 r/learnpython
2
9
March 18, 2022
🌐
Reddit
reddit.com › r/learnpython › [tkinter] why can't i create a square button?
r/learnpython on Reddit: [Tkinter] Why can't I create a square button?
July 11, 2018 -

Here are my codes:

from tkinter import *
window = Tk ()
window.title(" ")
window.geometry('600x600')

btn = Button(window, text ="X", bg = "white")
btn.config(height = 15, width = 15)
btn.grid(column = 0, row = 0)

window.mainloop()

I set the size of the button to be btn.config(height = 15, width = 15), which is supposed to be a square.

The window is a square but the button appears like this! The button is a rectangle! Besides, there is obviously something wrong when looking at the size ratio of the button to the window (which is window.geometry('600x600')) - the button should be very small (15x15 compared to 600x600)!

What's the problem? The window is a square but the button is a rectangle.

Anyone can run the codes and tell me what they see? Maybe it happens only to my PC?

🌐
Tcl Wiki
wiki.tcl-lang.org › page › tkinter.Button
tkinter.Button
The "normal" and "active" states will result in buttons of the same size. In "disabled" state, the button is drawn with the non-default button appearance without leaving space for the default appearance. The "disabled" state may result in a smaller button than the active state. height Specifies a desired height for the button.
🌐
TutorialsPoint
tutorialspoint.com › how-do-i-change-button-size-in-python-tkinter
How do I change button size in Python Tkinter?
October 4, 2024 - Button(win, text="Button-1", height=3, width=10).pack() Button(win, text="Button-2", height=5, width=15).pack() Button(win, text="Button-3", height=10, width=20).pack() #Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Set the geometry of frame win.geometry("600x600") # make the window non-resizable win.resizable(False, False) Button(win, text="Button-1",height= 3, width=10).pack() Button(win, text="Button-2",height=5, width=15).pack() Button(win, text= "Button-3",height=10, width=20).pack() # start the main loop win.mainloop()
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-dynamically-resize-button-text-in-tkinter
How To Dynamically Resize Button Text in Tkinter? | GeeksforGeeks
October 16, 2021 - In Tkinter there is no in-built function, that will change the button text size dynamically. ... Set bind, what bind will do, whenever button size change it will call resize function that we will create later. Inside the resize function, we will have a different condition, depends on the main window geometry/size. ... Step 1: Creates a normal Tkinter window.
🌐
TutorialKart
tutorialkart.com › python › tkinter › button › height
Tkinter Button height - Set Height of Button
February 3, 2025 - To set a specific height for a Button in Tkinter, pass the height parameter with the required number of text lines or pixels while creating the Button.
🌐
Reddit
reddit.com › r/learnpython › how do i make the buttons be square in tkinter?
r/learnpython on Reddit: How do I make the buttons be square in Tkinter?
March 18, 2022 -

I tried to do it with padx and pady by setting them to the same value, not square.

I tried to do it with width and height parameters also setting them to the same value, it's still not square.

I am stuck, does anyone know why these methods are not working and which ones do?

🌐
GitHub
github.com › lawsie › guizero › issues › 59
Can the size of a button be controlled in pixels · Issue #59 · lawsie/guizero
December 2, 2017 - Please close my old issue. Hello everyone, is there a way to control the size of a button in pixels not characters? Thanks for any help, LouisP
Author   LouisPi
🌐
Dafarry
dafarry.github.io › tkinterbook › button.htm
The Tkinter Button Widget
If you don’t specify a size, the button is made just large enough to hold its contents. You can use the padx and pady option to add some extra space between the contents and the button border. You can also use the height and width options to explicitly set the size.
🌐
Python Forum
python-forum.io › thread-43641.html
[Tkinter] Pixel sized button does not work associated method
Hello, Python Community I'm working on a calculator with tkinter. Actually, I'm learning Python to be able to teach to a friend of mine, I'm a (.Net C#) programmer, she's not. So I created 10 buttons for the digits, and their respective methods whi...
Top answer
1 of 2
5

If you want these widgets to be really perfectly aligned with one another, it's definitely better to align them on the same grid and use the sticky argument to make the buttons stretch to fill their cell:

import tkinter as tk

root = tk.Tk()

chLabel = tk.Label(root, text="Channel group")
channelButtons = tk.Frame(root, bg='yellow')
ch1Button = tk.Button(channelButtons, text="CH1 Settings")
ch1Button.pack(fill='x')
ch2Button = tk.Button(channelButtons, text="CH2 Settings")
ch2Button.pack(fill='x')
ch3Button = tk.Button(channelButtons, text="CH3 Settings")
ch3Button.pack(fill='x')
ch4Button = tk.Button(channelButtons, text="CH4 Settings")
ch4Button.pack(fill='x')

trigLabel = tk.Label(root, text="Trigger group")
trigButton = tk.Button(root, text="Trigger Settings")

horizLabel = tk.Label(root, text="Horizontal group")
horizButton = tk.Button(root, text="Horizontal settings")

# Align the labels and buttons in a 2-by-3 grid
chLabel.grid(row=0, column=0, pady=10)
trigLabel.grid(row=0, column=1, pady=10)
horizLabel.grid(row=0, column=2, pady=10)
channelButtons.grid(row=1, column=0, sticky='news')
trigButton.grid(row=1, column=1, sticky='news')
horizButton.grid(row=1, column=2, sticky='news')

root.mainloop()
2 of 2
2

The root of the problem is that you aren't taking advantage of the options available to pack and grid. For example, when you do .pack(side='left'), you are leaving it up to tkinter to decide how to vertically align the widget in the space allotted.

By default tkinter will center the items vertically. Since the native height of the various sections (channel group, trigger group, horizontal group) are slightly different, it prevents them from having the tops and/or bottoms perfectly aligned.

A simple fix is to use the "fill" option to have the widgets fill the space allocated to them. If you don't want them to fill the space allotted you can use the "anchor" option to have the widgets anchored to the top.

🌐
Stack Overflow
stackoverflow.com › questions › 21510156 › how-to-set-the-exact-height-of-an-element-in-tkinter
python - how to set the exact height of an element in Tkinter? - Stack Overflow
The 'height' value in the button measures lines of text, not pixels. So you have requested a box tall enough to draw 20 lines of text. Try reducing it to 1 or 2: button = tkinter.Button(row6, text = 'Send', height = 2, width = 20, relief = 'raised', cursor = 'hand1', font = ('times', 14, 'bold'))
🌐
Tutorialspoint
tutorialspoint.com › python › tk_button.htm
Tkinter Button
You can attach a function or a method to a button which is called automatically when you click the button. Here is the simple syntax to create this widget − ... options − Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas. Following are commonly used methods for this widget − ... from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") def helloCallBack(): msg=messagebox.showinfo( "Hello Python", "Hello World") B = Button(top, text ="Hello", command = helloCallBack) B.place(x=50,y=50) top.mainloop()