Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python tkinter single label with bold and normal text

My question is if there is a way to put in a single ttk.label() a text that show the full text with only some words in the bold font like this. I am doing this right now applying styles to many ttk.labels(), but this method imply that I must position every label next to the other, and that the program is multilingual, some strings don't fit correctly with the window. If there is a way to do this, it will be a great advantage to my work. Thanks.

like image 448
David González Blazman Avatar asked Oct 25 '16 10:10

David González Blazman


People also ask

How do you bold a label in Python?

The command fontweight='bold' can be used to make a textbox or label in figure bold.

Can you change the text of a label in tkinter?

Tkinter Label widgets are commonly used in applications to show text or images. You can change the label widget's text property, color, background, and foreground colors using different methods. You can update the text of the label widget using a button and a function if you need to tweak or change it dynamically.


1 Answers

No, you cannot change the attributes of only some of the characters in a Label widget. If you need to style individual character you need to use a small Text widget.

For example:

text = tk.Text(root, height=1, font="Helvetica 12")
text.tag_configure("bold", font="Helvetica 12 bold")

text.insert("end", "Hello, ") 
text.insert("end", "world", "bold") 
text.configure(state="disabled")
like image 72
Bryan Oakley Avatar answered Sep 30 '22 19:09

Bryan Oakley