等待点击Python龟
Waiting for click in Python Turtle
我想在 Python Turtle 中等待点击,然后再继续。代码大纲如下:
do_stuff()
# Wait for click and DO NOT continue if user has not clicked
# When user clicks:
do_other_stuff()
end()
SOF 上的回答提出了类似的问题,但建议的解决方案涉及扩展 Turtle class。我记得用更简单的方法来做到这一点,但想不起来了。
如有任何帮助,我们将不胜感激。
无需修改 turtle 或 wizardry,您可能会使用 tirtle.onclick。
do_stuff()
# Wait for click and DO NOT continue if user has not clicked
# When user clicks:
def second_part():
turtle.onclick(None)
do_other_stuff()
end()
turtle.onclick(second_part)
turtle.mainloop()
您甚至可以手动链接它们(未测试):
do_stuff()
def third_part():
turtle.onclick(None)
...
def second_part():
turtle.onclick(third_part)
...
turtle.onclick(second_part)
...
我想在 Python Turtle 中等待点击,然后再继续。代码大纲如下:
do_stuff()
# Wait for click and DO NOT continue if user has not clicked
# When user clicks:
do_other_stuff()
end()
如有任何帮助,我们将不胜感激。
无需修改 turtle 或 wizardry,您可能会使用 tirtle.onclick。
do_stuff()
# Wait for click and DO NOT continue if user has not clicked
# When user clicks:
def second_part():
turtle.onclick(None)
do_other_stuff()
end()
turtle.onclick(second_part)
turtle.mainloop()
您甚至可以手动链接它们(未测试):
do_stuff()
def third_part():
turtle.onclick(None)
...
def second_part():
turtle.onclick(third_part)
...
turtle.onclick(second_part)
...