Draw lines at the respective positions clicked by the mouse using Turtle Last Updated : 10 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will learn how to draw lines at any position which is clicked by the mouse using a turtle module. Turtle graphics: turtle.listen(): Using this then we can give keyboard inputsturtle.onscreenclick(func,1 or 3): This function is used to bind function to a mouse-click event on canvas. 1 means left click and 3 means to right-click.pen.goto(x coordinate , y coordinate): Moves the turtle from the current position to the location x, y along the shortest linear path between the two locations (i.e. a direct line between the current position and (x,y))pen.color( colour ): This method is used to change the color of the turtlepen.shape(shape): This method is used to give the shape to the turtlehead.penup: Picks the pen up so the turtle does not draw a line as it moveshead.hideturtle: This method is used to make the turtle invisible. It’s a good idea to do this while you’re in the middle of a complicated drawing because hiding the turtle speeds up the drawing observably. This method does not require any argument.head.clear: This function is used to delete the turtle's drawings from the screenhead.write: This function is used to write text at the current turtle position.Approach: Import the turtle modules.Define two instances for the turtle pen and head.Head is to tell currently at which coordinate mouse is clicked.Give shape and color to the instanceDefine the function btnclick which takes two parameters x and y coordinates, now use the function goto() inside this function to take the turtle to x and y coordinates passed in the parameter.Use onscreenclick to bind btnclick function with the mouse click on the screen.Use function listens to perform the above specified task.Below is the Python implementation of the above approach: Python # python program # import for turtle module import turtle # defining instance of turtle pen=turtle.Turtle() head=turtle.Turtle() head.penup() head.hideturtle() head.goto(0, 260) head.write("This is to display the coordinates of the position where mouse is clicked", align = "center", font = ("courier", 12, "normal")) # giving circle shape to pen i.e. instance of turtle pen.shape("circle") # giving colour to turtle pen.color("red") # define function to make the turtle move # to the position which is clicked by the mouse def btnclick(x, y): pen.goto(x, y) head.clear() head.write(f"x coordinate = {x}, y coordinate = {y}", align = "center", font = ("courier", 24, "normal")) # this function will call btnclick whenever mouse is clicked turtle.onscreenclick(btnclick, 1) turtle.listen() turtle.mainloop() Output: Comment More infoAdvertise with us Next Article How to draw 2-layered and colored spider web in Python using Turtle Module? K kashishmishra9911 Follow Improve Article Tags : Python Python-turtle Practice Tags : python Similar Reads How to draw 2-layered and colored spider web in Python using Turtle Module? Prerequisite: Python Turtle module Basics We all must have seen the spiderweb at our homes but have you ever wonder how many efforts and patience is required for building that. Let's salute the efforts of Spider and continue building one by ourselves. Spiderwebs usually comprise radical and spiral 1 min read Draw tree using Turtle module in Python Prerequisite: Turtle module, Drawing Triangle, Drawing Rectangle There are many modules in python which depicts graphical illustrations, one of them is turtle, it is an in-built module in Python, which lets the user control a pen(turtle) to draw on screen(drawing board). It is mostly used to illustr 2 min read Draw a Tic Tac Toe Board using Python-Turtle The Task Here is to Make a Tic Tac Toe board layout using Turtle Graphics in Python. For that lets first know what is Turtle Graphics. Turtle graphics In computer graphics, turtle graphics are vector graphics using a relative cursor upon a Cartesian plane. Turtle is drawing board like feature which 2 min read Draw a snowman using turtle module in Python Prerequisite: Turtle module, Drawing Shapes There are many modules in python which depicts graphical illustrations, one of them is turtle, it is an in-built module in Python, which lets the user control a pen(turtle) to draw on screen(drawing board). It is mostly used to illustrate figures, shapes, 2 min read Draw sun using Turtle module in Python Prerequisite: Turtle Programming in Python In this article, let's learn how to draw the Sun using turtle in Python. Turtle is an inbuilt module in Python. It helps draw patterns by providing a screen and turtle (pen) as tools. To move the turtle as desired functions defined within the module like fo 1 min read Displaying the coordinates of the points clicked on the image using Python-OpenCV OpenCV helps us to control and manage different types of mouse events and gives us the flexibility to operate them. There are many types of mouse events. These events can be displayed by running the following code segment : import cv2 [print(i) for i in dir(cv2) if 'EVENT' in i] Output : EVENT_FLAG_ 3 min read Like