Monday, November 18, 2024
Google search engine
HomeLanguagesturtle.undo() function in Python

turtle.undo() 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.undo()

This function is used to undo (repeatedly) the last turtle action. The number of available undo actions is determined by the size of the undobuffer. It doesn’t require any argument.

Syntax :

turtle.undo()

Below is the implementation of the above method with some examples :

Example 1 :

Python3




# import package
import turtle
  
# set speed
turtle.speed(1)
  
# motion
turtle.forward(100)
  
# undo previous motion
turtle.undo()


Output :

Example 2 :

Python3




# import package
import turtle
  
# set turtle
turtle.speed(1)
turtle.up()
turtle.setpos(-50,50)
turtle.down()
  
# motion
for i in range(4):
    turtle.forward(100)
    turtle.right(90)
      
# undo
for i in range(8):
    turtle.undo()


Output :

Example 3 :

Python3




# import package
import turtle
  
# set speed
turtle.speed(1)
  
# loop for motion
for i in range(4):
    
    # motion
    turtle.forward(100)
      
    # undo previous work
    turtle.undo()
      
    # turn
    turtle.left(90)


Output :

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments