Tkinter TTK Button Bold Font

PotatoBeenCrafted picture PotatoBeenCrafted · Mar 12, 2016 · Viewed 10.1k times · Source

First of all, thank you for taking the time to look at and read my question. What I'm trying to do is to make the font of a TTK button bold. It is very easy to do with a normal Tkinter button, but I'm having a little trouble with a TTK one.

Here's what I have for a normal Tkinter button:

boldFont = Font (size = 10, weight = "bold")
boldButton = Button (formatBar, text = "B", width = 2, font = boldFont)
boldButton.pack (side = LEFT, padx = 1, pady = 1)

And that achieves what I would like, but when I try the same thing with a TTK button (using a TTK style instead of a font), it doesn't make the text bold.

TTK button:

boldStyle = ttk.Style ()
boldStyle.configure ("Bold.TButton", size = 10, weight = "bold")
boldButton = ttk.Button (formatBar, text = "B", width = 2, style = "Bold.TButton")
boldButton.pack (side = LEFT, padx = 1, pady = 1)

I'm probably just being a little stupid, but I can't find any way to fix this. I've done a little research and tried converting some TCL code, but none of it works.

Answer

DavedeKoning picture DavedeKoning · Mar 12, 2016

Try this:

boldStyle.configure("Bold.TButton", font = ('Sans','10','bold'))
boldButton = ttk.Button(formatBar, text = "B", width = 2, style = "Bold.Button")

Found it here.

You could of course change the font type to any type you like (if available :))