How to put part of a text in bold in Tkinter?

Asked

Viewed 2,507 times

5

I need to display a text in a GUI interface made with Tkinter, however, I would like only one word in the middle of this text to be in bold.

I’m using it this way:

texto = Label(Frame, text="Texto qualquer com mais de 5 linhas", font= fonte qualquer, bold)

Of course this way the whole text is in bold.

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

2 answers

1

It’s not possible even with this widget. The solutions people use are to use another control that renders the text the way you want it to or create a function that assembles some Labels as if it were one. It is a beautiful gambiarra but it usually works. A response in the OS did this:

def customLabel(parent, row, column, bold, standard):
    cLabelFrame = Frame(parent)
    cLabelFrame.grid(row=row, column=column)
    Label(cLabelFrame, text=bold, font=('bold').grid(column=0)
    Label(cLabelFrame, text=standard).grid(column=1)

I put in the Github for future reference.

0

I got a nice response from a user in Ggoogle, the idea was the following:

You can take a look at the "tag_config" and "mark_set" functions of the Tkinter.Text component (here). In case you would have to replace your Tkinter.Label component with a Tkinter.Text (leaving it disabled for clear editing...)

I did this and it worked well, I managed to put several formatting, then I deactivated the edges, editing and finally I put the color as the default color.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.