Open In App

turtle.exitonclick()-Python

Last Updated : 25 Aug, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

turtle.exitonclick() method is used in the Turtle graphics module to keep the drawing window open until the user clicks inside it. Unlike turtle.done(), which leaves the window open indefinitely, exitonclick() binds the bye() function to a mouse click, so the window will close only when clicked once.

Syntax

turtle.exitonclick()

  • Parameters: None
  • Returns: Nothing
  • Belongs to: Screen class (not available for TurtleScreen instances)

Example :

python
import turtle

for i in range(3):
  turtle.circle(40)
  turtle.right(120)

turtle.exitonclick()

Output :

Explanation:

  • for loop draws 3 circles with the turtle, turning 120° after each circle to form a triangular pattern.
  • After the drawing is complete, the turtle graphics window remains open.
  • turtle.exitonclick() method waits for the user to click anywhere inside the window.
  • When the user clicks, it calls bye() internally and closes the window.

Related Articles


Article Tags :
Practice Tags :

Explore