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 :