如何在Python中查找当前鼠标位置并将其集成到龟中? 我宁愿如果你没有使用任何非内置模块(下载模块) 任何答案,将不胜感激在Python turtle中查找光标的当前位置
2
A
回答
-1
按照turtle docs你可以使用:
turtle.position()
哦,等等 - 你问对于鼠标的位置... ...研究
turtle.onscreenclick()
这显然只在你点击鼠标按钮时才起作用。
0
我们可以进入乌龟的Tk基础,以启用'<Motion>'
事件。我投的功能设置/取消该事件看起来像乌龟屏幕的方法,但你可以调用它的奇异画面实例turtle.Screen()
:
import turtle
def onmove(self, fun, add=None):
"""
Bind fun to mouse-motion event on screen.
Arguments:
self -- the singular screen instance
fun -- a function with two arguments, the coordinates
of the mouse cursor on the canvas.
Example:
>>> onmove(turtle.Screen(), lambda x, y: print(x, y))
>>> # Subsequently moving the cursor on the screen will
>>> # print the cursor position to the console
>>> screen.onmove(None)
"""
if fun is None:
self.cv.unbind('<Motion>')
else:
def eventfun(event):
fun(self.cv.canvasx(event.x)/self.xscale, -self.cv.canvasy(event.y)/self.yscale)
self.cv.bind('<Motion>', eventfun, add)
def goto_handler(x, y):
onmove(turtle.Screen(), None) # avoid overlapping events
turtle.setheading(turtle.towards(x, y))
turtle.goto(x, y)
onmove(turtle.Screen(), goto_handler)
turtle.shape('turtle')
onmove(turtle.Screen(), goto_handler)
turtle.mainloop()
我的代码包括例如运动事件处理程序,使龟像追逐激光指示器的猫一样跟随光标。没有必要的点击(除了最初的点击使窗口激活)。:
相关问题
- 1. 使用htmleditorextender查找文本框的当前光标位置
- 2. 如何在flex4的textArea中找到当前光标位置?
- 3. 如何在使用jQuery的文本框中查找光标的当前位置?
- 4. 在android中查找当前位置
- 5. 查找当前位置
- 6. Java粘贴到当前光标位置
- 7. 获取当前键盘光标位置
- 8. 在RichTextBox中查找鼠标光标位置的坐标
- 9. 查找当前位置到另一个位置的标题
- 10. Python。返回当前光标位置和位置最后一次鼠标点击
- 11. 当前查看范围或光标位置的MS Word插件
- 12. 通过光标/光标位置获取当前语句
- 13. jquery - 我如何找到当前光标位置
- 14. 在QT中查找当前鼠标位置
- 15. 查找jQuery可拖动光标位置
- 16. 查找当前位置的坐标并找出国家
- 17. Appcelerator:查找图片的当前位置
- 18. 查找当前文件的位置
- 19. 在Selenium中显示当前光标位置
- 20. 在Word中获取当前光标位置(VSTO)
- 21. 在记事本++插件中获取当前光标位置
- 22. vim在当前光标位置放置一行到下一行
- 23. 如何查找当前位置列表中最近的位置坐标?
- 24. ckeditor - 获取当前光标位置的前一个字符
- 25. 删除Vim中的当前行而不管光标的位置
- 26. 在vb.net的文本框中查找光标位置
- 27. 需要在MS Word中捕捉当前滚动位置(不是光标位置)
- 28. 获取webrowser控件中当前光标位置的链接ID
- 29. 跳转到Xcode中的当前光标位置
- 30. 如何检测TextWatcher Android中当前光标位置的变化?