Ali Naghshi
Ali Naghshi

Reputation: 35

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

I'm trying to code an whiteboard program so I need to have something like Ctrl-Z (Undo) function in it.

Upvotes: 2

Views: 443

Answers (2)

Red
Red

Reputation: 27567

Like pointed out in this great answer, there is a handy undo function built into turtle.

To elaborate, here is the turtle.undo function's documentation that can be accessed through print(help(turtle.undo)) or 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()
   ...

See this answer for the implementation.

Upvotes: 1

Pretzel
Pretzel

Reputation: 8301

There IS an undo function called (drumroll) undo() !

Ex: turtle.undo()

Apparently the number of Undos is limited by the UndoBuffer.

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

Upvotes: 2

Related Questions