Как получить координату экрана в Python Turtle?

Опубликовано: 16 Марта, 2022

Turtle - это специальная функция в Python, которая содержит графическую библиотеку. В этой статье мы узнаем, как получить координату экрана в Python Turtle.

Turtle has many built in function to create this program we use following.

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 increse 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

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

Next
Draw Color Filled Shapes in Turtle - Python
Recommended Articles
Page :
Article Contributed By :
sunny18bcs1027
@sunny18bcs1027
Vote for difficulty
Article Tags :
  • Python-turtle
  • Python
  • Python Programs
Report Issue
Python

РЕКОМЕНДУЕМЫЕ СТАТЬИ