turtle.setundobuffer() 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.setundobuffer()
This function is used to set or disable undobuffer. It takes the size parameter. If the size is an integer an empty undobuffer of a given size is installed. Size gives the maximum number of turtle-actions that can be undone by the undo() function. If the size is None, no undobuffer is present.
Syntax :
turtle.setundobuffer(size)
Below is the implementation of the above method with some examples :
Example 1 :
Python3
# importing packageimport turtle# check default value of undobufferprint(turtle.undobufferentries())# set undo buffer by 10 as valueturtle.setundobuffer(10)# loop executes 50 times with# turtle.forward(1) statement# i.e; undobufferentries gives 50for i in range(50): turtle.forward(1) # but gives 10 as it is set alreadyprint(turtle.undobufferentries()) |
Output :
0 10
Example 2 :
Python3
# importing packageimport turtle# print default valueprint(turtle.undobufferentries())# loop for motionfor i in range(50): # one statement increase the # undobuffer entries turtle.fd(1) # print undobuffer entries ie; 50# due to above loop with one statementprint(turtle.undobufferentries())# set undobuffer to Noneturtle.setundobuffer(None)# print undobuffer entries# i.e; value set by set undobufferprint(turtle.undobufferentries()) |
Output :
0 50 0



