I'm trying to code an whiteboard program so I need to have something like Ctrl-Z (Undo) function in it.
I'm trying to code an whiteboard program so I need to have something like Ctrl-Z (Undo) function in it.
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/
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.