Python 3.0 使用 turtle.onclick

Python 3.0 using turtle.onclick(Python 3.0 使用 turtle.onclick)
本文介绍了Python 3.0 使用 turtle.onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

所以这是我的问题,我必须为我的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reading *.mhd/*.raw format in python(在 python 中读取 *.mhd/*.raw 格式)
Count number of cells in the image(计算图像中的单元格数)
How to detect paragraphs in a text document image for a non-consistent text structure in Python OpenCV(如何在 Python OpenCV 中检测文本文档图像中的段落是否存在不一致的文本结构)
How to get the coordinates of the bounding box in YOLO object detection?(YOLO物体检测中如何获取边界框的坐标?)
Divide an image into 5x5 blocks in python and compute histogram for each block(在 python 中将图像划分为 5x5 块并计算每个块的直方图)
Extract cow number from image(从图像中提取奶牛编号)