turtle.ondrag() function in Python Improve Improve Like Article Like Save Share Report The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses tkinter for the underlying graphics, it needs a version of Python installed with Tk support. turtle.ondrag() This function is used to bind fun to mouse-move event on this turtle on canvas. Syntax : turtle.ondrag(fun, btn, add) Parameters : fun : a function with two arguments, to which will be assigned the coordinates of the clicked point on the canvas btn : number of the mouse-button defaults to 1 (left mouse button) add : True or False. If True, new binding will be added, otherwise it will replace a former binding Below is the implementation of the above method with an example : Example : # importing package import turtle # method to call on drag def fxn(x, y): # stop backtracking turtle.ondrag(None) # move the turtle's angle and direction # towards x and y turtle.setheading(turtle.towards(x, y)) # go to x, y turtle.goto(x, y) # call again turtle.ondrag(fxn) # set turtle speed turtle.speed(10) # make turtle screen object sc = turtle.Screen() # set screen size sc.setup(400, 300) # call fxn on drag turtle.ondrag(fxn) # take screen in mainloop sc.mainloop() Output : Last Updated : 17 Aug, 2020 Like Article Save Article Previous turtle.home() function in Python Next Interesting Facts about PYGAME Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads turtle.forward() method in Python-Turtle turtle.setpos() and turtle.goto() functions in Python turtle.stamp() function in Python turtle.Screen().bgcolor() function in Python turtle.distance() function in Python turtle.hideturtle() function in Python turtle.title() function in Python turtle.width() function in Python turtle.shape() function in Python turtle.write() function in Python Like D deepanshu_rustagi Follow Article Tags : Python-turtle Python Practice Tags : python