i need some help writing a GUI for the program i'm making. it is a simple text-based number-guessing game and i would like to have the prompts displayed in a nice window.
i would also like to have the "number_guesses" and the "guess_list" variables displayed off to the right of the prompts, and get updated dynamically.
heres my code so y'all can understand what i'm talking about:
import random, time
number = random.randint(1,50)
running = True
guess_str = "Guess the number I'm thinking of between 1 and 50, then press enter: "
number_guesses = 0
play_again = ""
yes_in = ["true", "yes", "t", "y", "affirmitive"]
guess_list = []
def play():
global number, running, guess_str, number_guesses
while running:
guess = raw_input(guess_str)
try:
guess = int(guess)
if number_guesses == 10:
print "Sorry, you lost!"
running = False
elif guess == number:
number_guesses += 1
print "Congrats, you guessed it! It took you", number_guesses, "guesses."
running = False
elif number < guess < (number + 15):
number_guesses += 1
guess_str = "Your guess was a little high... Guess again: "
print "Guesses left: ", (10 - number_guesses)
if guess in guess_list:
guess_str = "You have already guessed that. Try again: "
elif guess not in guess_list:
guess_list.append(guess)
print "You have guessed: ", guess_list
elif number > guess > (number - 15):
number_guesses += 1
guess_str = "Your guess was a little low... Guess again: "
print "Guesses left: ", (10 - number_guesses)
if guess in guess_list:
guess_str = "You have already guessed that. Try again: "
elif guess not in guess_list:
guess_list.append(guess)
print "You have guessed: ", guess_list
elif guess < (number + 15):
number_guesses += 1
guess_str = "Your guess was very low... Guess again: "
print "Guesses left: ", (10 - number_guesses)
if guess in guess_list:
guess_str = "You have already guessed that. Try again: "
elif guess not in guess_list:
guess_list.append(guess)
print "You have guessed: ", guess_list
else:
number_guesses += 1
guess_str = "Your guess was very high... Guess again: "
print "Guesses left: ", (10 - number_guesses)
if guess in guess_list:
guess_str = "You have already guessed that. Try again: "
elif guess not in guess_list:
guess_list.append(guess)
print "You have guessed: ", guess_list
except:
guess_str = "The value you inserted is not an integer. Try again: "
continue
def reset():
global number, running, guess_str, number_guesses, play_again
number = random.randint(1,50)
running = True
guess_str = "Guess the number I'm thinking of between and 50, then press enter: "
number_guesses = 0
guess_list = []
play_again = str(raw_input("Play again? (yes/no, then enter) "))
def playAgain():
global play_again, yes_in
if play_again.lower()in yes_in:
play_total()
else:
print "Thanks for playing!"
time.sleep(1)
quit()
def play_total():
play()
reset()
playAgain()
play_total()
thanks for any tips, and know that i will likely not know what you're talking about, because i don't have any experience with wxPython.
billy
btw: tips on the script in general are welcome!