10

This is my problem, I was building an interface for a program, but for needs of the bosses, the font must be larger. I have changed the font size of every widget without any problem, but with the ttk.Buttons, I was unable to change it... I was reading that ttk.Button doesn't support the font attribute, but tk.Button supports it. I tried with tk.Button and it works, but I don't like the graphic style of this tk.Button...

Is there any way to change the font style and size of a ttk.Button, or changed the graphic style of the tk.Button to make similar to the ttk?

Thanks to everyone!

2 Answers2

25

You have to use styles to customize ttk widgets.

s = ttk.Style()
s.configure('my.TButton', font=('Helvetica', 12))
b = ttk.Button(mainframe, text='Press me', style='my.TButton',
command=foo)
Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • 4
    Does `font` take any other arguments? For example `font=('Helvetica', 12, 'bold', 'justify'))`. Is argument order important? – Siemkowski Apr 23 '18 at 20:19
  • @Siemkowski The expression `(…, …, …)` is a __tuple__. In this case the font name is required, while the size and style are optional. Yes, the order is important, since there are no names to identify the values. – Manngo Sep 08 '21 at 06:50
2

The Above answer is correct and you can change the style for all of ttk widgets(for example font) you can change the root's style whose name is '.':

s = ttk.Style()
s.configure('.', font=('Helvetica', 12))

After that, all of your ttk widgets's uses 'Helvetica' font in size '12'. The answer, derived from "https://tkdocs.com/shipman/ttk-style-layer.html"