Is there a way to disable the resize of a ttk Button? So that I can maximaze the text inside the button.
I tried to set the size of the buttons with config(width, height) which didn't work, so I used ipadx and ipady. But the button size is not fixed permanently and changes when the text size is changed.
One of the way is to put the ttk.Button
inside a frame with specified width
and height
in pixels and make the button to fill the frame:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.config(padx=10, pady=10)
s = ttk.Style()
s.configure("my.TButton", font=("", 28)) # set the font size to whatever you like
### ttk.Button put inside a frame with specified width and height in pixels
frame = ttk.Frame(root, width=200, height=50)
frame.pack()
btn = ttk.Button(frame, text="Hello World", style="my.TButton")
# make the button to fill the parent frame
btn.place(x=0, y=0, relwidth=1, relheight=1)
### ttk.Button without using frame
ttk.Button(root, text="Hello World", style="my.TButton").pack()
root.mainloop()
Output: