1

I am looking for a way to underline each word in a label text per condition I've set.

I looked for similar questions posed before and I've only managed to either Underline the entire text at once or one single letter. My app is essentially supposed to be a text typing application. For now i'm tracking each word, I would like to Underlining the upcoming word. here's my code.

    from tkinter import *
    from tkinter import font

    class App:
        def __init__(self):
            self.root = Tk()
            self.count = 0
            l = Label(text="Hello, world")
            l.pack()
            f = font.Font(l,l.cget("font"))
            f.configure(underline = True)
            l.configure(font=f)
            self.root.mainloop()

    if __name__ == "__main__":
        app=App()

For example purposes one can use the self.root.after(mili, method)

I'm using tkinter python 3.6.6 Thanks in advance.

  • You'll need to use a `Text` widget instead. There's no way to have different fonts in a single Label. – Novel Aug 27 '18 at 22:59
  • I've done it with both the Text and Message widget, but as soon as i turn them to "disabled", which is what i would need so that i cannot easily copy the text, it thus becomes difficult or improbable to retrieve the text to manipulate it's font or tag. I just thought because there is a way to highlight 1 letter in a label and a way to highlight the whole thing. Then surely there would be a way to maybe loop through each letter or word somehow. :thinking: – blaise johnny Aug 27 '18 at 23:19

1 Answers1

1

You can't highlight individual words in a Label widget. If you need that capability, you will need to use a Text widget.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685