I am very new to programming. I want to run the guessing game in a graphics window(as opposed to just in idle).
Im really stuck on how to get the user inputs from the graphics window to go through the while loop and then output back onto the graphics window.
This is the code i have so far. The guessing game itself works in idle, it is just a matter of getting it to work in the window.
Thanks
from random import *
from graphics import *
def main(max):
#window
win=GraphWin("The Guessing Game",700,700)
win.setCoords(0.0,0.0,3.0,5.0)
win.setBackground("ivory")
Text(Point(1.5,4.5),"\nI'm thinking of a number between 1 and 100.").draw(win)
Text(Point(1.5,4.2), "Try to guess the number in as few attempts as possible.No more than 10!\n").draw(win)
Text(Point(1,3), "Your Guess").draw(win)
Text(Point(1,1),"Answer").draw(win)
input=Entry(Point(2,3),5)
input.setText("0.0")
input.draw(win)
output=Text(Point(2,1),"")
output.draw(win)
button=Text(Point(1.5,2.0), "Guess")
button.draw(win)
Rectangle(Point(1,1.5),Point(2,2.5)).draw(win)
win.getMouse()
#game
print("\tGuess the number!")
print("\nI'm thinking of a number between 1 and 100.")
print("Try to guess the number in as few attempts as possible.No more than 10!\n")
num = randrange(101)
tries = 0
guess = ""
while guess != num:
guess = int(input("Take a guess: "))
if guess > num:
print("Too high.")
elif guess < num:
print ("Too low.")
tries += 1
if tries >= max:
print("Sorry, you took too many guesses. Game Over")
exit()
print("Congratulations!")
again =input("To play again press Enter. Type anything else to quit.")
if again == "":
main(max)
else:
exit()
main(10)
This post has been edited by kyle91st: 11 March 2010 - 05:47 PM

New Topic/Question
Reply




MultiQuote



|