4

我正在努力学习 Python。我需要这个循环继续滚动,直到我点击屏幕。

我尝试使用win.getMouse,但它不工作。

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
4

2 回答 2

3

将 True 作为条件可确保代码一直运行,直到它被等于 'hello' 的 n.strip() 破坏。

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

while关于循环的 Python 文档

于 2017-09-13T12:46:44.483 回答
2

你可以checkMouse()改用。它基本上检查用户是否点击了屏幕上的任何地方。

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

假设http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node2.html是正确的,并且您的其余代码都很好。

于 2015-03-30T01:27:22.623 回答