Skip to content Skip to sidebar Skip to footer

Hangman Cannot Update Image One By One

from tkinter import * from tkinter import messagebox import random class homewindow(object): def __init__(self,win): self.words = ['rainbow','geography','testimonial'

Solution 1:

If self.wrong is the number of wrong guesses, then it should be updated inside letter_guess and not in display_word():

def letter_guess(self,letter):
    self.data = self.entry.get()
    self.guess_list += self.data
    if self.data not in self.hidden_wd:
        self.wrong += 1  # increment self.wrong
        self.times -= 1
        if self.times == 0:
            messagebox.showwarning('Lose','Game Over')
    self.display_word()
    self.display_guess()

def display_word(self):
    self.guessed = ''
    for i in self.hidden_wd.lower():
        if i in self.guess_list:
            self.guessed += i
        else:
            self.guessed += '*'
            # removed self.wrong += 1
    self.lb1.configure(image=self.photo_list[self.wrong])
    self.lb2.configure(text=self.guessed)
    if '*' not in self.guessed:
        messagebox.showinfo('Hangmaner','Congraulations')

Post a Comment for "Hangman Cannot Update Image One By One"