如何在Python Turtle 中获取屏幕坐标?
Turtle 是Python中的一个特殊功能,它包含一个图形库。在本文中,我们将学习如何在Python Turtle 中获取屏幕坐标。
Turtle 有许多内置函数来创建我们使用的这个程序。
import turtle –> This is the python library which allow us to access turtle library.
Turtle()–> This Method is used to make object.
onscreenclick(functionname,1) –> This is turtle function which sends the coordinate to function; 1 is for left click and 3 is for Right click
speed()–> This is used to increase or decrease the speed of turtle pointer.
listen()–> This allows the server to listen to incoming connections.
done()–> This is used to hold the the screen.
Python3
# turtle library
import turtle
#This to make turtle object
tess=turtle.Turtle()
# self defined function to print coordinate
def buttonclick(x,y):
print("You clicked at this coordinate({0},{1})".format(x,y))
#onscreen function to send coordinate
turtle.onscreenclick(buttonclick,1)
turtle.listen() # listen to incoming connections
turtle.speed(10) # set the speed
turtle.done() # hold the screen