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
相关用法
- Python Wand function()用法及代码示例
- Python Sorted()用法及代码示例
- Python Numbers choice()用法及代码示例
- Python Tkinter askopenfile()用法及代码示例
- Python ord()用法及代码示例
- Python sum()用法及代码示例
- Python round()用法及代码示例
- Python id()用法及代码示例
- Python vars()用法及代码示例
注:本文由纯净天空筛选整理自deepanshu_rustagi大神的英文原创作品 turtle.setundobuffer() function in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。