I want to make all the tkinter buttons the same size regardless of text. Is it possible to stretch other buttons to match each other or set a specific size? As I am having difficulty finding how to do so in the documentation. Currently the buttons stretch based on the size of the text. Example of what I mean. Is it possible to make them all the same size?
You would typically do this when you use a geometry manager (pack
, place
, or grid
).
Using grid:
import tkinter as tk
root = tk.Tk()
for row, text in enumerate((
"Hello", "short", "All the buttons are not the same size",
"Options", "Test2", "ABC", "This button is so much larger")):
button = tk.Button(root, text=text)
button.grid(row=row, column=0, sticky="ew")
root.mainloop()
Using pack:
import tkinter as tk
root = tk.Tk()
for text in (
"Hello", "short", "All the buttons are not the same size",
"Options", "Test2", "ABC", "This button is so much larger"):
button = tk.Button(root, text=text)
button.pack(side="top", fill="x")
root.mainloop()
You can also use width
option while defining your buttons like this:
from tkinter import *
root = Tk()
button = Button(root, text = "Test", width = 5)
button.grid()
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With