Make a Label Bold Tkinter
Asked Answered
P

4

27

How do I make a Label in Tkinter Bold ?

This is my code

labelPryProt=Label(frame1,text="TEXTTEXT")
labelPryProt.pack(side=LEFT,fill=BOTH,expand=False)
labelPryProt.configure(font=("Helvetica",BOLD, 18))#this is not working not making the text as bold

What is the error ?

Predella answered 29/9, 2017 at 18:42 Comment(2)
no effect for the samePredella
NameError: name 'bold' is not definedPredella
B
41

You don't have to configure it separately, you can pass an argument when you are creating the widget:

labelPryProt = Label(frame1, text='TEXTTEXT', font='Helvetica 18 bold')
Brandabrandais answered 29/9, 2017 at 18:45 Comment(5)
What if I have to change it later ?Predella
Let's say I allow user to change the text type so how to configure that ? how to change it without declaring the variable again labelPryProt = Label()Predella
Sure, than you'll have to configure it. labelPryProt.configure(font='Helvetica 18 bold')Brandabrandais
@zzz123: the better solution is to use a font object, so you only have to change it in one place. See tkdocs.com/tutorial/fonts.htmlLolitaloll
This answer is definitely wrong. The question explicitly asks about making a tk Label bold. The answer here is about something else involving the Helvetica font and the font size 18. => -1Primordial
C
17

You have to put bold in quotes, like this: label = Label(frame1, text='Hello', font=('Helvetica', 18, 'bold')) . This method works for me.

Conceptionconceptual answered 17/6, 2018 at 20:5 Comment(0)
S
7

Just put bold in the quotes, example : label = Label(frame1, text = "TEXTTEXT", font = ('Helvetica', 18, 'bold')) That work for me, configure also work but you have to make one more line of code. If you want, I can show you how to .configure: Just add this code : label.configure(font=("Helvetica","bold", 18))

Thanks. :)

Shammer answered 7/6, 2021 at 9:22 Comment(2)
Here's your first upvote for suggesting .configure. Welcome to Stack Overflow.Lubow
It should be label.configure(font=("Helvetica", 18, "bold")), not label.configure(font=("Helvetica","bold", 18)).Idou
P
2

almost right! but replace font size with font type

tkinter.Label(frame1, text='Hello', font=('Helvetica', 18, 'bold'))

Placentation answered 1/7 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.