turtle.resetscreen() function in Python

The turtle.resetscreen() function resets all turtles on the screen to their initial state and clears the drawing. It also resets the background.

Syntax: turtle.resetscreen()
Parameters: None.

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

Demo50.py

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

import turtle

window = turtle.Screen()
t1 = turtle.Turtle()
t2 = turtle.Turtle()

t1.forward(100)
t2.backward(100)

turtle.resetscreen()  # Reset all turtles and clear screen

window.exitonclick()

The following is the output:

turtle.resetscreen() 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 turtles: t1 = turtle.Turtle() and t2 = turtle.Turtle() create two independent turtles.
  • Move t1 forward: t1.forward(100) draws a 100-unit line in its current heading (default east).
  • Move t2 backward: t2.backward(100) moves 100 units opposite its heading (default west).
  • Reset screen: turtle.resetscreen() clears the entire canvas, removes all turtle drawings, and reinitializes the screen and turtles to defaults (all turtles reset to start state).
  • 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.reset() function in Python
turtle.Screen().setup() function in Python
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment