📜  Python中的 turtle.setundobuffer()函数

📅  最后修改于: 2022-05-13 01:55:41.198000             🧑  作者: Mango

Python中的 turtle.setundobuffer()函数

turtle 模块以面向对象和面向过程的方式提供海龟图形原语。因为它使用 Tkinter 作为底层图形,所以它需要安装一个支持 Tk 的Python版本。

turtle.setundobuffer()

该函数用于设置或禁用 undobuffer。它采用大小参数。如果大小是整数,则安装给定大小的空撤消缓冲区。 Size 给出了 undo()函数可以撤消的最大海龟动作数。如果大小为无,则不存在撤消缓冲区。

句法 :

turtle.setundobuffer(size)

以下是上述方法的实现以及一些示例:

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


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



输出 :

0
10

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


输出 :

0
50
0