Changing ttk button height in Python

This seems like a dumb question, but is it possible to manually change the height of the ttk button?

Something like button = tkinter.Button(frame, text='hi', width=20, height=20...) works fine for the tkinter button. Although I would prefer to use the ttk button, because it looks much better aesthetically.

button = ttk.Button(frame, text='hi', width=20, height=20...) does not work, the height does not seem valid. I tried to configure it with config or look for elements in style to change them and they were out of luck.

Is there a simple solution? I am using Python 2.7, Windows for writing. Sorry, this seems like trivial questions, but I looked around without much happiness.

+8
tkinter ttk
source share
3 answers

To answer your question, no, you cannot do this. All dots of thematic buttons - ensure the same size.

That being said, there is a lot of room for ready thinking. For example, you can pack a button into a frame, turn off the distribution of geometry on the frame (so that the size of the frame controls the size of the button, and not vice versa), and then set the frame size to the position you want.

Or try placing a transparent image on the button you need, then use the compound option to overlay the invisible image.

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

Finally, you can put the button in the grid, make it sticky on all sides, and then set the minimum height for this row.

Of course, if you are on OSX, all bets are disabled - he really wants to make buttons of a certain size.

+5
source share

Just an example, as @Bryan said: β€œFor example, you can pack a button in 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) 
+2
source share

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 add pixels inside the button, unlike pady and padx , which adds pixels outside the button

0
source share

All Articles