from tkinter import *
man = Tk()
#---------------------
man.geometry(“650x500”)
man.title(“Hang Man”)
man.configure(bg=“grey”)
#---------------------
score = 0
#Functions-------------
def WordPicker():
return “happiness”
CurrentWord = WordPicker()
def Scorer(Word):
if len(entry.get()) == 1:
if entry.get() in word:
score += 1
else:
score -=1
else:
score -= 1
if score < 0:
abs(score)
else:
score += 0
return score
CurrentScore = Scorer(CurrentWord)
def Hang_man():
if CurrentScore == 0:
TheHangMan.config(image=hang7)
elif CurrentScore == 1:
TheHangMan.config(image=hang6)
elif CurrentScore == 2:
TheHangMan.config(image=hang5)
elif CurrentScore == 3:
TheHangMan.config(image=hang4)
elif CurrentScore == 4:
TheHangMan.config(image=hang3)
elif CurrentScore == 5:
TheHangMan.config(image=hang2)
elif CurrentScore == 6:
TheHangMan.config(image=hang1)
#Canvas---------------
background = Canvas(man,bg=“dark grey”,width=600,height=400)
background.place(x=0,y=0)
#Entry----------------
entry = StringVar()
textbox = Entry(man,textvariable=entry,bg=“light grey”)
textbox.place(x=10,y=410)
#---------------------
#Button---------------
button = Button(man,text=“PUSH ME!”,command=Hang_man,bg=“dark grey”)
button.place(x=10,y=450)
#---------------------
#Labels---------------
ScoreLabel = Label(man,text="Score: " + str(score))
ScoreLabel.place(x=650,y=100)
#---------------------
#Image----------------
hang1 = PhotoImage(file=“h1.gif”)
hang2 = PhotoImage(file=“h2.gif”)
hang3 = PhotoImage(file=“h3.gif”)
hang4 = PhotoImage(file=“h4.gif”)
hang6 = PhotoImage(file=“h5.gif”)
hang7 = PhotoImage(file=“h6.gif”)
hang7 = PhotoImage(file=“h7.gif”)
global TheHangMan
TheHangMan = Label(man,image=hang1)
TheHangMan.place(x=0,y=0)
#------------------------
Traceback (most recent call last):
File “C:\Users\hatim\Desktop\files\programs\python programs\hang man\Hang_Man.py”, line 30, in
CurrentScore = Scorer(CurrentWord)
File “C:\Users\hatim\Desktop\files\programs\python programs\hang man\Hang_Man.py”, line 16, in Scorer
if len(entry.get()) == 1:
NameError: name ‘entry’ is not defined
What is the problem with the program?