My code reads from a binary, converts the hex into images and disposes them onto a canvas.
I can click to a single tile on the canvas and change it properly. But I am now aware that I absolutely need an undo command (like a common CRTL+Z
).
So I created a stack_list=[]
. Inside my function clickA
, which is the function that changes the selected tile, I have inserted this code:
stack_list.append(clickA)
If I run print(stack_list)
I obtain [<function clickA at 0x00000226B0CA9CA0>]
.
Then I wrote another function:
def undo():
if not stack_list:
return
previous = stack_list.pop(-1)
print(stack_list)
and attached it to a button. It seems to works because print(stack_list)
gives me []
but the original state is not restored.
It is possible to obtain the original state without having to "fake an original state" (for i.e. by storing the original image into a variable and then call it back)?