How to change the color of a specific word in a tkinter label

68 Views Asked by At

I'm new to tkinter and I'm trying to change the color and background of a specific word in a label when I press "Return". The code works, but it changes the color of the entire label, and I don't know how I can specify it so it only changes the color of the first word on the label (w_1). This is the code I have:

,Thank you!

from tkinter import *
import random

root = Tk()

list_1 = ["about","above","add","after","again","air","all","almost","along","also","always","America","an"]
w_1 = random.choice(list_1)
w_2 = random.choice(list_1)
w_3 = random.choice(list_1)
w_4 = random.choice(list_1)
w_5 = random.choice(list_1)

def color(event):
   list_label.config(fg="#808080")

list_label = Label(root, text=w_1 + " " + w_2 + " " + w_3 + " " + w_4 + " " + w_5, width=30)
list_label.grid(row=1, column=0, pady=5, padx=150)

root.bind("<Return>", color)

root.mainloop()


0

There are 0 best solutions below