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 packageimport turtle # set speedturtle.speed(1) # motionturtle.forward(100) # undo previous motionturtle.undo() |
Output :

Example 2 :
Python3
# import packageimport turtle # set turtleturtle.speed(1)turtle.up()turtle.setpos(-50,50)turtle.down() # motionfor i in range(4): turtle.forward(100) turtle.right(90) # undofor i in range(8): turtle.undo() |
Output :

Example 3 :
Python3
# import packageimport turtle # set speedturtle.speed(1) # loop for motionfor i in range(4): # motion turtle.forward(100) # undo previous work turtle.undo() # turn turtle.left(90) |
Output :























Please Login to comment...