Friday, December 5, 2025
HomeLanguagesturtle.onrelease() function in Python

turtle.onrelease() function in Python

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.onrelease()

This function is used to bind fun to the mouse-button-release event on this turtle on canvas.

Syntax :

turtle.onrelease(fun, btn=1, add=None)

Parameters:

Arguments        Description                                                                                                                                                                   
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 :

Python3




# import package
import turtle
  
# methods to action
def fxn1(x,y):
   turtle.fillcolor("blue")
def fxn2(x,y):
   turtle.fillcolor("white")
      
# set screen and turtle
sc=turtle.Screen()
sc.setup(400,300)
  
turtle.shape("turtle")
turtle.turtlesize(2)
turtle.speed(1)
  
# allow user to click for some action
turtle.onclick(fxn1)
  
# allow user to release for some action
turtle.onrelease(fxn2)


Output :

Here we can find that :

  • whenever the user click (yellow-colored dot on  arrow) on turtle it changes to the blue color, and
  • after releasing (yellow dot disappears) from the screen it changes to white color.
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32427 POSTS0 COMMENTS
Milvus
98 POSTS0 COMMENTS
Nango Kala
6802 POSTS0 COMMENTS
Nicole Veronica
11944 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12010 POSTS0 COMMENTS
Shaida Kate Naidoo
6931 POSTS0 COMMENTS
Ted Musemwa
7182 POSTS0 COMMENTS
Thapelo Manthata
6881 POSTS0 COMMENTS
Umr Jansen
6867 POSTS0 COMMENTS