所以这是我的问题,我必须为我的 CS 课制作一张照片,在海龟中进行估计真的很令人沮丧.我打算使用 .onclick() 来显示我的位置.
So here is my problem, I have to make a picture for my CS class and it is really frustrating estimating in turtle. I planed to use .onclick() to show me to position.
import turtle as t
def getPos(x,y):
print("(", x, "," ,y,")")
return
def main():
t.onclick(getPos)
t.mainloop()
main()
海龟文档似乎说 onclick 将在一个接受两个变量的函数中传递坐标.
The turtle documentation seems to say that the onclick will pass the coordinates in a function that takes in two variables.
http://docs.python.org/3.1/library/turtle.html#turtle.onclick
注意:当我单击箭头时它会起作用,但这不是我想要的.我想点击屏幕上的其他位置来找出我应该将箭头发送到哪个坐标!
NOTE: It works when I click on the arrow head, but thats not what I want. I want to click some other position on the screen to find out what coordinates I should send the arrow head to!
任何帮助将不胜感激.
好吧,我想出了一个解决办法.它不是一个完美的解决方案,但效果很好.因为只有当你点击箭头时 onclick 才会响应,所以我让箭头包含了整个屏幕.然后我把它藏了起来.你需要做的是将鼠标悬停在你想去的位置上,按a",当它变黑时点击屏幕.然后外壳将显示您需要的坐标.确保你总是回到 (1000,0).
Alright, I figured out a work around. Its not a perfect solution but it works pretty well. Because onclick will only respond if you click on the arrow head, I made the arrow head encompass the entire screen. Then I hid it. What you need to do is hover over the position you want to go to, press "a" and when it goes black click the screen. The shell will then display the coordinates you need. Make sure you always go back to (1000,0).
import turtle as t
def showTurtle():
t.st()
return
def getPos(x,y):
print("(", x, "," ,y,")")
return
def hideTurtle(x,y):
t.ht()
return
def main():
t.speed(20)
t.shapesize(1000,1000)
t.up()
t.goto(1000,0)
t.ht()
t.onkey(showTurtle,"a")
t.listen()
t.onclick(getPos)
t.onrelease(hideTurtle)
t.mainloop()
main()
另外,如果我班上的任何人发现这个,我是宾厄姆顿的一名 CS 学生,如果你使用这个,我建议不要留下任何痕迹.教授已经看到了这一点,并且会认出它.
Also, in case anyone from my class finds this, I am a CS student in binghamton and if you use this I recommend leaving no trace. The prof has seen this and will recognize it.
这篇关于Python 3.0 使用 turtle.onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在python中的感兴趣区域周围绘制一个矩形How to draw a rectangle around a region of interest in python(如何在python中的感兴趣区域周围绘制一个矩形)
如何使用 OpenCV 检测和跟踪人员?How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
如何在图像的多个矩形边界框中应用阈值?How to apply threshold within multiple rectangular bounding boxes in an image?(如何在图像的多个矩形边界框中应用阈值?)
如何下载 Coco Dataset 的特定部分?How can I download a specific part of Coco Dataset?(如何下载 Coco Dataset 的特定部分?)
根据文本方向检测图像方向角度Detect image orientation angle based on text direction(根据文本方向检测图像方向角度)
使用 Opencv 检测图像中矩形的中心和角度Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 检测图像中矩形的中心和角度)