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

Put the objects in a list or dictionary and draw the appropriate object each time there is a miss.

win = GraphWin("Test", 500, 650)
start_x = 200

object_dict  = {}

obj = Circle(Point(start_x,200),50)
object_dict[0] = obj
 
ctr = 1
for ln in ((0, 150,    0, 100),
           (0, 100,    -100, 100),
           (-100, 100, -100, 500),
           (0, 250,    0, 380),
           (0, 380,    -50, 450),
           (0, 380,    50, 450),
           (0, 300,    -50, 380),
           (0, 300,    50, 380)):
    obj = Line(Point(start_x+ln[0], ln[1]), Point(start_x+ln[2], ln[3]))
    object_dict[ctr] = obj
    ctr += 1

rect = Rectangle(Point(start_x-100,350),Point(start_x+170,400))
rect.setWidth(3)
object_dict[ctr] = rect
ctr += 1
 
rect2 = Rectangle(Point(start_x-100,400),Point(start_x+100,600))
rect2.setWidth(3)
object_dict[ctr] = rect2

win.getMouse()     ## start game

## simulate wrong guesses
ctr = 0
while ctr < len(object_dict):
    object_dict[ctr].draw(win)
    ctr += 1
    print "wrong guess #", ctr
    time.sleep(1.0)
win.getMouse()
win.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.