How are you guys doing today? I'm having a hard time with my CS project. I have to write a hangman python code but it is kinda different from what I've seen around. I'll post my code and then explain what I am having trouble with:
from hangman_support import *
def isalpha(s):
if s.isalpha():
return True
return False
def print_word(word1, wordbox):
temp_word = ""
for c in word1:
temp_word += c + " "
wordbox.setText(temp_word)
def main():
win = GraphWin('Hangman', WINSIZE, WINSIZE)
headpoint = draw_gallows(win, WINSIZE)
wordbox = draw_word_box(win, WINSIZE)
entrybox = draw_entry_box(win, WINSIZE)
messagebox = draw_message_box(win, WINSIZE)
try:
s = 'hangman.txt'
infile = open(s, "r")
s.isalpha()
data = readfile1(infile)
infile.close()
data = data.split()
word1 = data[0]
blank_word = ""
for c in word1:
blank_word += ('_')
print_word(blank_word, wordbox)
guessed = ""
for s in word1:
wait_for_guess(win, WINSIZE)
guess = entrybox.getText()
guessed += guess
messagebox.setText(guessed)
draw_head(win, headpoint)
print('guess: ', guess)
wait_for_guess(win, WINSIZE)
guess = entrybox.getText()
guessed += guess
messagebox.setText(guessed)
draw_body(win, headpoint)
print('guess: ', guess)
wait_for_guess(win, WINSIZE)
guess = entrybox.getText()
guessed += guess
messagebox.setText(guessed)
draw_limb(win, headpoint, True, True)
print('guess: ', guess)
wait_for_guess(win, WINSIZE)
guess = entrybox.getText()
guessed += guess
messagebox.setText(guessed)
draw_limb(win, headpoint, False, True)
print('guess: ', guess)
wait_for_guess(win, WINSIZE)
guess = entrybox.getText()
guessed += guess
messagebox.setText(guessed)
draw_limb(win, headpoint, True, False)
print('guess: ', guess)
wait_for_guess(win, WINSIZE)
guess = entrybox.getText()
guessed += guess
messagebox.setText(guessed)
draw_limb(win, headpoint, False, False)
messagebox.setText('You Lose!')
win.getMouse()
win.close()
except IOError:
print('Error! Could not open file.')
def readfile1(infile):
data = infile.read()
return data
main()
I am having problems on filling the secret word when the user's guess is correct. I have no idea how to do that in this code, can you guys please help me? Thank you in advance,
BWall