4

I'm trying to learn Python. I need this loop to keep rolling until I click on the screen.

I tried using win.getMouse but it's not working.

win = GraphWin("game of life", 600, 600)    
win.setCoords(-1, -3, s+1, s+1)

q = True
while q:
    board = iterate(board)
    x = 0
    while x < s:
        y = 0
        while y < s:
            update_color(x, y, board, rec)
            y = y + 1
        x = x + 1
    if win.getMouse():
        q = False
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Raul Quinzani
  • 493
  • 1
  • 4
  • 16

2 Answers2

3

Having True as a condition ensures that the code runs until it's broken by n.strip() equaling 'hello'.

while True:
    n = raw_input("Please enter 'hello':")
    if n.strip() == 'hello':
        break

Python docs about while loop

n00dl3
  • 21,213
  • 7
  • 66
  • 76
Erzi
  • 39
  • 3
2

You can use checkMouse() instead. It basically checks if the user has clicked anywhere on the screen yet.

win = GraphWin("game of life", 600, 600)  
win.setCoords(-1, -3, s+1, s+1)

q = True
while q:
    board = iterate(board)
    x = 0
    while x < s:
        y = 0
        while y < s:
            update_color(x, y, board ,rec)
            y = y + 1
        x = x + 1
    if win.checkMouse() is not None:  # Checks if the user clicked yet
        q = False  # Better to use the break statement here

Assuming http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node2.html is correct and that the rest of your code is good.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
jkd
  • 1,045
  • 1
  • 11
  • 27