Saturday, October 18, 2025
HomeLanguagesturtle.setundobuffer() function in Python

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 package
import turtle
 
# check default value of undobuffer
print(turtle.undobufferentries())
 
# set undo buffer by 10 as value
turtle.setundobuffer(10)
 
# loop executes 50 times with
# turtle.forward(1) statement
# i.e; undobufferentries gives 50
for i in range(50):
      turtle.forward(1)
     
# but gives 10 as it is set already
print(turtle.undobufferentries())


 
 

Output :

 

0
10

 

Example 2 :

 

Python3




# importing package
import turtle
 
# print default value
print(turtle.undobufferentries())
 
# loop for motion
for i in range(50):
   
    # one statement increase the
    # undobuffer entries
    turtle.fd(1)
     
# print undobuffer entries ie; 50
# due to above loop with one statement
print(turtle.undobufferentries())
 
# set undobuffer to None
turtle.setundobuffer(None)
 
# print undobuffer entries
# i.e; value set by set undobuffer
print(turtle.undobufferentries())


 
 

Output :

 

0
50
0

 

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

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS