turtle.undo() function in Python
Last Updated :
26 Jul, 2020
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 turtle
turtle.speed( 1 )
turtle.forward( 100 )
turtle.undo()
|
Output :
Example 2 :
Python3
import turtle
turtle.speed( 1 )
turtle.up()
turtle.setpos( - 50 , 50 )
turtle.down()
for i in range ( 4 ):
turtle.forward( 100 )
turtle.right( 90 )
for i in range ( 8 ):
turtle.undo()
|
Output :
Example 3 :
Python3
import turtle
turtle.speed( 1 )
for i in range ( 4 ):
turtle.forward( 100 )
turtle.undo()
turtle.left( 90 )
|
Output :
Share your thoughts in the comments
Please Login to comment...