[Python] How do I get multiple buttons in a list to flash color in Tkinter?

Discussão em 'Python' iniciado por Stack, Janeiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a ahngman GUI, currently the program creates buttons according to the number of letters in a random word and stores those in a list. In case of a correct guess i need the selected buttons to flash green, and in case of an incorrect one, all buttons that are not guessed to flash red.

    def guess(event):
    guess = str(entry.get()).lower()
    entry.delete(0, 'end')
    if guess and len(guess) == 1 and guess.isalpha():
    attabel.config(text=attempts-1)
    if guess in word_list:
    label.config(text = "CORRECT")
    guesses = [i for i in range(len(word_list)) if word_list == guess]
    for j in guesses:
    letters[j].config(text=guess, bg = "green")
    else:
    label.config(text="WRONG")
    else:
    label.config(text = "use actual letters")




    that's what I have as of right now, I tried after() method,

    letters[j].after(200, lambda: letters[j].config(bg="white"))



    but it only worked for the last element of the array. Or just skipped the change of color to green altogether. Thank you in advance.

    Continue reading...

Compartilhe esta Página