You could use a prompt.

prompt = ("TEST")
label1 = Label(root, text=prompt, width=len(prompt), bg='yellow')
label1.pack()

i got a text in a text widget, how would highlight text that's in a tkinter text widget, i think you cant put lables ontop of a text widget ?

Here try this.

import Tkinter as tk

root = tk.Tk()
text = tk.Text(root, font=("Helvetica", 50))
text.pack()

text.insert(tk.END, "Hello, World")
#Designate what letters to highlight
#in this case Hello and W is highlighted
text.tag_add("Hello", "1.0", "1.5")
text.tag_add("W", "1.7", "1.8")
text.tag_config("Hello", background="yellow", foreground="blue")
text.tag_config("W", background="black", foreground="green")

root.mainloop()

thanks for your great example, can you please explain what does the numbers in the text.tag_add do, "1.0" "1.5" ?

so for example if i wanted to highlight all the l in a text i would have to pick out each position ?

Vegaseat has a nice example in the "Python GUI Programming" sticky, but I refuse to be someone else's research assistant. If memory serves it is somewhere in the middle of the thread's pages.

it still doesnt work do you know where im going wrong ???

def highlight(seq):
    #remove highlights
    if "highlight" in Text.tag_names():
        Text.tag_delete("highlight")

        i = len(seq)
        index = "1.0"
        while True:
            index = Text.search(seq, index, nocase=1, stopindex='end')
            if index:
                index2 = Text.index("%s+%d" % (index, i))
                Text.tag_add("highlight", index, index2)
                Text.tag_config("highlight", background="yellow")
                index = index2
            else: return
button4 = ttk.Button(content,text="highlight", command=lambda:highlight("s"))
This article has been dead for over six months. Start a new discussion instead.