Python中的turtle.setundobuffer()函数
turtle模块以面向对象和面向过程的方式提供Turtle图形基元。因为它使用 Tkinter 作为底层图形,它需要安装一个支持 Tk 的 Python 版本。
turtle.setundobuffer()
该函数用于设置或禁用undobuffer。它接受size参数。如果 size 是一个整数,就会安装一个给定大小的空 undobuffer。size给出了可以被undo()函数撤销的最大龟速动作数。如果大小为None,则不存在任何undobuffer。
语法 :
turtle.setundobuffer(size)
下面是上述方法的实现和一些例子:
例子 1 :
# 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())
输出 :
0
10
例子2 :
# 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())
输出 :
0
50
0