turtle.setundobuffer() function in Python (original) (raw)

Last Updated : 17 May, 2021

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())

`