Nov-04-2024, 11:47 PM
Hi,
I have asked this before and searched online. The answers i am getting are just far beyond where I am up to. My code may not be the most efficient nor may it be pretty but i know I am close and with a tweak here or there - anyway i am reaching out.
The premise is simple a hangman game that changes the image when a wrong letter is guessed. On the button click it has to update the label. Here is what i have so far.
photo1Label.config(image = photo+str(counter),bd=0)
I have also tried having a helper variable. That also doesn't work.
bob = photo1+counter
photo1Label.config(image = bob,bd=0)
Been tearing my hair out.
Thanks in advance for reading and supporting
I have asked this before and searched online. The answers i am getting are just far beyond where I am up to. My code may not be the most efficient nor may it be pretty but i know I am close and with a tweak here or there - anyway i am reaching out.
The premise is simple a hangman game that changes the image when a wrong letter is guessed. On the button click it has to update the label. Here is what i have so far.
import tkinter from tkinter import messagebox window = tkinter.Tk() window.title("a title") window.geometry("400x600") window.configure(background = "green") def checkans(): if user_inp.get() in letters: tkinter.messagebox.showinfo("CONGRATULATIONS","You have guessed a correct letter") else: tkinter.messagebox.showinfo("INCORRECT","That letter is not in the word") photo1Label.config(image = photo2,bd=0) letters = ["h","o","m","e"] photo1 = tkinter.PhotoImage(file = "hang1.png") photo2 = tkinter.PhotoImage(file = "hang2.png") photo3 = tkinter.PhotoImage(file = "hang3.png") photo4 = tkinter.PhotoImage(file = "hang4.png") photo1Label = tkinter.Label(window, image = photo1,bd=0) photo1Label.image = photo1 photo1Label.place(x=100,y=210) user_inp = tkinter.Entry(window,width=15) user_inp.place(x=155,y=420) check_guess = tkinter.Button(window,width=12,text="check if correct",fg="black",bg="gold",command=checkans) check_guess.place(x=155,y=447) window.mainloop()I am figuring that if i can get the label config to update to something like this it might work but it doesnt seem to like it.
photo1Label.config(image = photo+str(counter),bd=0)
I have also tried having a helper variable. That also doesn't work.
bob = photo1+counter
photo1Label.config(image = bob,bd=0)
Been tearing my hair out.
Thanks in advance for reading and supporting