So I have the following code:
I'd like the user to press ENTER when the black box is around either GREEN or RED. But how do I have Python ready for a key input (Python 3.x on OS X) and have it quit the loop with the isYesSelected be 1 or 0.
Thanks!!
Code:
from graphics import *
import random, time
import math
import curses
def main():
win=GraphWin("CONTINUE?", 800, 800)
isYesSelected = "0"
while True:
rect = Rectangle(Point(190,190), Point (310,310))
rect.draw(win)
rect.setFill('black')
rect.setOutline('black')
rect = Rectangle(Point(200,200), Point (300,300))
rect.draw(win)
rect.setFill('green')
rect.setOutline('green')
rect = Rectangle(Point(490,190), Point (610,310))
rect.draw(win)
rect.setFill('white')
rect.setOutline('white')
rect = Rectangle(Point(500,200), Point (600,300))
rect.draw(win)
rect.setFill('red')
rect.setOutline('red')
win.nodelay("1")
win.getch()
time.sleep(0.5)
rect = Rectangle(Point(190,190), Point (310,310))
rect.draw(win)
rect.setFill('white')
rect.setOutline('white')
rect = Rectangle(Point(200,200), Point (300,300))
rect.draw(win)
rect.setFill('green')
rect.setOutline('green')
rect = Rectangle(Point(490,190), Point (610,310))
rect.draw(win)
rect.setFill('black')
rect.setOutline('black')
rect = Rectangle(Point(500,200), Point (600,300))
rect.draw(win)
rect.setFill('red')
rect.setOutline('red')
time.sleep(0.5)
main()
I'd like the user to press ENTER when the black box is around either GREEN or RED. But how do I have Python ready for a key input (Python 3.x on OS X) and have it quit the loop with the isYesSelected be 1 or 0.
Thanks!!