使用Turtle graphic的onscreenclick()事件,但需要从绑定到i的函数返回值

2024-10-01 11:19:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是一些代码,将函数绑定到鼠标点击turtle图形屏幕上:

import turtle
wn = turtle.Screen()

def token_move(x,y):
    turtle.goto(x,y)
    position = [turtle.xcor(), turtle.ycor()]
    return position

token = turtle.Turtle()
wn.onscreenclick(token_move)

现在我的问题是,我需要海龟在鼠标点击后的坐标,这样我就可以在程序的其余部分使用它,但是因为它绑定到onscreenclick()事件,所以不能从token_move返回任何值。我试着把最后一行改成:

^{pr2}$

但也没有运气。任何帮助都将不胜感激!在


Tags: 函数代码importtoken图形move屏幕def