当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python turtle.setundobuffer()用法及代码示例


turtle 模块以面向对象和面向过程的方式提供 turtle 图形基元。由于它使用Tkinter作为基础图形,因此需要安装有Tk支持的Python版本。

turtle .setundobuffer()

该函数用于设置或禁用undobuffer。它采用size参数。如果大小为整数,则会安装给定大小的空撤销缓冲区。大小给出了undo()函数可以撤消的最大turtle-actions数。如果大小为无,则不存在撤消缓冲区。

用法:

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; undobufferenteries gives 50 
for i in range(50):
      turtle.forward(1) 
      
# but gives 10 as it is set already 
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 enteries 
    turtle.fd(1) 
      
# print undobuffer enteries ie; 50 
# due to above loop with one statement 
print(turtle.undobufferentries()) 
  
# set undobuffer to None 
turtle.setundobuffer(None) 
  
# print undobuffer enteries 
# i.e; value set by set undobuffer 
print(turtle.undobufferentries())

输出:

0
50
0



相关用法


注:本文由纯净天空筛选整理自deepanshu_rustagi大神的英文原创作品 turtle.setundobuffer() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。