Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter TTK Button Bold Font

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.

like image 534
PotatoBeenCrafted Avatar asked Mar 12 '16 21:03

PotatoBeenCrafted


1 Answers

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 :))

like image 157
DavedeKoning Avatar answered Sep 18 '22 10:09

DavedeKoning