turtle.reset() function in Python

The turtle.reset() function clears the screen, re-centers the turtle, and resets all of its attributes (color, size, etc.) to their default values.

Syntax: turtle.reset()
Parameters: None.

Let us see an example to implement the turtle.reset() function in Python:

Demo49.py

# turtle.reset() function in Python
# Code by Studyopedia

import turtle

window = turtle.Screen()
t = turtle.Turtle()

t.forward(100)
t.left(90)
t.forward(50)

t.reset()  # Reset turtle to initial state and clear drawings

window.exitonclick()

The following is the output:

turtle.reset() function in Python

In the above code, we followed the below steps:

  • Import module: import turtle loads the turtle graphics library.
  • Create screen: window = turtle.Screen() opens the drawing window.
  • Create turtle: t = turtle.Turtle() creates the turtle you’ll control.
  • Move forward: t.forward(100) draws a 100-unit line (pen is down by default).
  • Turn left: t.left(90) rotates the turtle 90° counterclockwise.
  • Move forward again: t.forward(50) draws another line in the new direction.
  • Reset turtle: t.reset() clears all drawings and returns the turtle to its initial state: centered at (0, 0), heading east, pen down, default colors/size/shape/speed.
  • Close on click: window.exitonclick() waits for a mouse click, then closes the window.

If you liked the tutorial, spread the word and share the link and our website, Studyopedia, with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

turtle.pos() function in Python
turtle.resetscreen() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment