How to put part of a bold text in Tkinter?

5

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

I'm using it as follows:

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.

    
asked by anonymous 29.07.2015 / 13:56

2 answers

1

This is not even possible with this widget . The solutions people use are to use another control that renders the text the way you want it or create a function that bundles some labels as if it were one. It is a beautiful gambiarra but it usually works. An answer in the SO 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)
    
29.07.2015 / 14:13
0

I got a nice response from a user on Ggoogle, the idea was this:

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 fine, I was able to put a lot of formatting, then I deactivated the borders, editing and finally I put the color as the default color.

    
31.07.2015 / 20:52