Changing ttk Button Height in Python

This worked for me:

my_button = ttk.Button(self, text="Hello World !")
my_button.grid(row=1, column=1, ipady=10, ipadx=10)

where ipady and ipadx adds pixels inside the button unlike pady and padx which adds pixels outside of the button


Just an example, as @Bryan said, "For example, you can pack the button into a frame", I did it like this:

import Tkinter as tk
import ttk

class MyButton(ttk.Frame):
    def __init__(self, parent, height=None, width=None, text="", command=None, style=None):
        ttk.Frame.__init__(self, parent, height=height, width=width, style="MyButton.TFrame")

        self.pack_propagate(0)
        self._btn = ttk.Button(self, text=text, command=command, style=style)
        self._btn.pack(fill=tk.BOTH, expand=1)

To directly answer your question, no, you can't do this. The whole point of themed buttons is to provide a uniform size.

That being said, there's plenty of room for out-of-the-box thinking. For example, you can pack the button into a frame, turn geometry propagation off on the frame (so the size of the frame controls the size of the button rather than visa versa), then set the size of the frame to whatever you want.

Or, try putting a transparent image on the button that is the height you desire, then use the compound option to overlay the label over the invisible image.

Or, create a custom theme that uses padding to get the size you want.

Finally, you can put the button in a grid, have it "sticky" to all sides, then set a min-height for that row.

Of course, if you are on OSX all bets are off -- it really wants to make buttons a specific size.

Tags:

Tkinter

Ttk