我已经做了一个简单的程序,让你可以点击屏幕上的东西绘制使用海龟。你移动到的每个点都记录在一个数组中。我想在用户完成绘制时使用JSON将这个数组写入文本文件。你知道吗
import turtle
from turtle import Turtle, Screen
pastMovementsX = [0]
pastMovementsY = [0]
screen = Screen()
screen.setup(500, 350)
screen.screensize(600, 600)
def move(x, y):
moveto = turtle.goto(x, y)
pastMovementsX.append(turtle.xcor())
pastMovementsY.append(turtle.ycor())
turtle.onscreenclick(move)
turtle.onscreenclick()
之后的任何代码都不会运行。我假设它一直在检查屏幕上的点击,因此无法继续程序。你知道吗
我试过两件事。尤其是线程和多处理。它不起作用,经过一点研究后,turtle模块似乎不喜欢或不适合线程/多处理。你知道吗
如何让程序在按键后停止turtle.onscreenclick()
并继续执行进一步的代码?你知道吗
你的问题是无效的,因为你的前提是不正确的:
onclick()
方法设置一个处理函数并继续执行下一个语句,它不检查任何东西。这是由tkinter事件循环完成的,它由程序中的最后一个mainloop()
调用传递到。你知道吗我的猜测是您没有正确地考虑代码计划执行的操作序列,并且描述这些操作可能有助于解决实际问题。你知道吗
相关问题 更多 >
编程相关推荐