我想等待 Python Turtle 中的点击,然后再继续。代码概要如下:
do_stuff()
# Wait for click and DO NOT continue if user has not clicked
# When user clicks:
do_other_stuff()
end()
SOF 上的This 答案提出了类似的问题,但提出的解决方案涉及扩展 Turtle 类。我记得用了一种更简单的方法来做到这一点,但记不起了。
任何帮助将不胜感激。
在不修改海龟或魔法的情况下,您可能可以使用 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)
...
将这些行放在脚本末尾对我来说效果很好
def screenclick(x, y): 出口() 海龟.onscreenclick(屏幕点击) 乌龟.mainloop()