Move the turtle to the place where you click the mouse with turtle in Python

Move the turtle to the place where you click the mouse with turtle in Python

Execution image

スクリーンショット 2020-04-15 4.23.00.png

Sample program

import turtle

kame = turtle.Turtle("turtle")

def moveKame(x, y):
    kame.goto(x, y)

kame.screen.onclick(moveKame)

turtle.done()

Commentary

#Load the turtle module
import turtle
#Create and store a Turtle in the turtle module in a variable named kame
kame = turtle.Turtle("turtle")
#Define a function named moveKame
#def means that it will generate a function
#moveKame can be any name
# x,y is the value of the coordinates clicked with the mouse
def moveKame(x, y):
    #Move the turtle
    kame.goto(x, y)
#Register a mouse click event. (The moveKame function is executed when the mouse is clicked.)
kame.screen.onclick(moveKame)
#Do not close the window immediately when running the program.
turtle.done()

Recommended Posts

Move the turtle to the place where you click the mouse with turtle in Python
[Part.2] Crawling with Python! Click the web page to move!
Convert the image in .zip to PDF with Python
Move what you installed with pip to the conda environment
In the python command python points to python3.8
Output the contents of ~ .xlsx in the folder to HTML with Python
Try logging in to qiita with Python
Display Python 3 in the browser with MAMP
To work with timestamp stations in Python
If you want to include awsebcli with CircleCI, specify the python version
How to get the date and time difference in seconds with python
Upload what you got in request to S3 with AWS Lambda Python
[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
How to use the C library in Python
Log in to the remote server with SSH
[Python] Get the files in a folder with Python
Load the network modeled with Rhinoceros in Python ③
[REAPER] How to play with Reascript in Python
Convert PDFs to images in bulk with Python
[Python] Created a class to play sin waves in the background with pyaudio
The easiest way to synthesize speech with python
Try to solve the man-machine chart with Python
[Automation] Extract the table in PDF with Python
Specify the Python executable to use with virtualenv
To dynamically replace the next method in python
Until you run the changefinder sample in python
Say hello to the world with Python with IntelliJ
Draw graphs in Julia ... Leave the graphs to Python
[Python] Draw a Mickey Mouse with Turtle [Beginner]
Log in to Yahoo Business with Selenium Python
Use PIL in Python to extract only the data you want from Exif
The easiest way to use OpenCV with python
The trick to write flatten concisely in python
Visualize the timeline of the number of issues on GitHub assigned to you in Python
Load the network modeled with Rhinoceros in Python ②
Introduction to Python with Atom (on the way)
What you want to memorize with the basic "string manipulation" grammar of python
I'm new to Python. Could you please tell me where the error is?
How to get the files in the [Python] folder
How to use tkinter with python in pyenv
Load the network modeled with Rhinoceros in Python ①
I want to display the progress in Python!
How to get a list of files in the same directory with python
Introducing the book "Creating a profitable AI with Python" that allows you to learn machine learning in the shortest course
Run the output code with tkinter, saying "A, pretending to be B" in python
System trade starting with Python3: Bio-health stocks to look at in the new Corona
How to identify the element with the smallest number of characters in a Python list?
Software that saves the set character string to the clipboard when you click the [Python] button
[Note] How to write QR code and description in the same image with python
[For beginners] Web scraping with Python "Access the URL in the page to get the contents"
It is easy to execute SQL with Python and output the result in Excel
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error
How to retrieve the nth largest value in Python
I tried to graph the packages installed in Python
How to convert / restore a string with [] in python
How to get the variable name itself in python
Try to solve the programming challenge book with python3
How to get the number of digits in Python
Complement the library you put in anaconda with jedi-vim
How to do hash calculation with salt in Python