turtle.onscreenclick(turtle.goto)
for i in range(4):
turtle.forward(30)
turtle.left(90)
if turtle.position() == (within square region):
Activate function()
import turtle
def goto_inside(x, y):
if 0 <= x <= 30 and 0 <= y <= 30:
turtle.goto(x, y)
turtle.onscreenclick(goto_inside)
# draw a square 30x30
for i in range(4):
turtle.forward(30)
turtle.left(90)
# turtle.mainloop()
你需要计算出正方形所定义的区域的范围,这样以后你就可以比较鼠标点击的位置,看看它们是否在里面。这是一个完整的程序,它首先允许通过单击来定义正方形的左下角,绘制它,然后每次在矩形区域内单击鼠标时调用指定的函数。在
如果您的意思是只允许
goto
进入正方形:相关问题 更多 >
编程相关推荐