Open In App

Python – turtle.exitonclick()

Last Updated : 17 Aug, 2020
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.exitonclick() :

This function is used to Go into mainloop until the mouse is clicked. It doesn’t require any argument. Bind bye() method to mouseclick on TurtleScreen. If using_IDLE – value in configuration dictionary is False (default value), enter mainloop. If IDLE with -n switch (no subprocess) is used, this value should be set to True in turtle.cfg. In this case IDLE’s mainloop is active also for the client script.

This is a method of the Screen-class and not available for TurtleScreen instances.

Syntax : turtle.exitoncick()
Parameters : None
Returns : Nothing

Below is the implementation of above method with an example :

Example :




# import package
import turtle
  
# loop for motion
for i in range(3):
  turtle.circle(40)
  turtle.right(120)
  
# exit from the screen 
# if and only if
# mouse is clicked
turtle.exitonclick()


Output :

Here we can see that :

  • Turtle screen is loaded
  • Turtle draw some stuff
  • Turtle window remain as it is
  • When user click (yellow colored sign) on turtle window it closes i.e; exit on click.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads