2024-10-01 11:31:21 发布
网友
基本上,我想访问两次鼠标点击的坐标,然后我甚至必须使用这些坐标执行操作
我已经找到了这段代码,但它是无限运行的,并没有按照我想要的方式在两次之后终止
import turtle def get_mouse_click_coor(x, y): print(x, y) turtle.onscreenclick(get_mouse_click_coor) turtle.mainloop()
下面的方法怎么样。单击窗口两次,然后使用两个坐标调用do_whatever():
do_whatever()
from turtle import Screen, Turtle from functools import partial def do_whatever(start, end): ''' Replace the body of this function. ''' turtle.penup() turtle.goto(start) turtle.pendown() turtle.goto(end) def get_mouse_click_1(x, y): screen.onclick(partial(get_mouse_click_2, (x, y))) def get_mouse_click_2(position, x, y): screen.onclick(None) do_whatever(position, (x, y)) screen = Screen() turtle = Turtle() turtle.hideturtle() screen.onclick(get_mouse_click_1) screen.mainloop()
下面的方法怎么样。单击窗口两次,然后使用两个坐标调用
do_whatever()
:相关问题 更多 >
编程相关推荐