乌龟有类似 Ctrl-Z(撤消)功能的东西吗?

Does turtle something like a Ctrl-Z (Undo) function?

我正在尝试编写一个白板程序,所以我需要在其中添加类似 Ctrl-Z(撤消)功能的东西。

有一个撤销函数叫做 (drumroll) undo() !

例如:turtle.undo()

显然Undos的数量受UndoBuffer的限制。

来源:https://www.geeksforgeeks.org/turtle-undo-function-in-python/

正如在 中指出的那样,turtle 中内置了一个方便的 undo 函数。

为了详细说明,这里是 turtle.undo 函数的文档,可以通过 print(help(turtle.undo))print(turtle.undo.__doc__):

访问

undo()

undo (repeatedly) the last turtle action.

No argument.

undo (repeatedly) the last turtle action. Number of available undo actions is determined by the size of the undobuffer.

Example:

   >>> for i in range(4):
   ...     fd(50); lt(80)
   ...
   >>> for i in range(8):
   ...     undo()
   ...

参见 this 实施答案。