I am trying to code the hangman game.. i have the game running but i need to attach it to graphics.py. please help it needs to be done by midnight.
here is my code so far the last parts just the ideas to atach it to graphics.
from graphics import*
from random import *
win = GraphWin("Hangman",700,700)
def readfile():
infile = open("C:\\Users\\Pelin\\Desktop\\wordlist.txt","r")
contents = infile.read()
lines = contents.split("\n")
return lines
def random(lines):
secret_word = randint(0,len(lines)-1)
return lines[secret_word].lower()
def play(secret_word):
guess = 0
solution = []
for i in range(len(secret_word)):
solution.append("_")
num_incorrect = 0
while num_incorrect < 7 and "_" in solution:
print(" ".join(solution))
guess = input("Enter a letter")
if secret_word.find(guess)==-1:
num_incorrect = num_incorrect +1
else:
i = secret_word.find(guess)
solution[i] = guess
if not '_' in solution:
print("Congratulations!")
print(secret_word)
else:
print("You Lost")
print(secret_word)
def main():
words = readfile
()
play(random(words))
circ = Circle(Point(500,200),50)
circ.draw(win)
line = Line(Point(500,150),Point(500,100))
line.draw(win)
line1 = Line(Point(500,100),Point(400,100))
line1.draw(win)
line2 = Line(Point(400,100),Point(400,500))
line2.draw(win)
line3 = Line(Point(500,250),Point(500,380))
line3.draw(win)
line4 = Line(Point(500,380),Point(450,450))
line4.draw(win)
line5 = Line(Point(500,380),Point(550,450))
line5.draw(win)
line6 = Line(Point(500,300),Point(450,380))
line6.draw(win)
line7 = Line(Point(500,300),Point(550,380))
line7.draw(win)
rect = Rectangle(Point(100,350),Point(370,400))
rect.draw(win)
rect = Rectangle(Point(100,400),Point(300,600))
rect.draw(win)
def create-graphics(win)
Text(...)
En = Entry(...)
Rectangle(...)
Text(...)
return en
def enter-guess(win,en)
win.getMouse()
guess = en.getText()
return guess