I have wrote a code that it working fine to move the image to bottom, but I am confused how to move it again to the old position of image that is on the top ?
import tkinter as tk
def move_object(canvas, object_id, destination, speed=50):
dest_x, dest_y = destination
coords = canvas.coords(object_id)
current_x = coords[0]
current_y = coords[1]
new_x, new_y = current_x, current_y
delta_x = delta_y = 0
if current_x < dest_x:
delta_x = 1
elif current_x > dest_x:
delta_x = -1
if current_y < dest_y:
delta_y = 1
elif current_y > dest_y:
delta_y = -1
if (delta_x, delta_y) != (0, 0):
canvas.move(object_id, delta_x, delta_y)
if (new_x, new_y) != (dest_x, dest_y):
canvas.after(speed, move_object, canvas, object_id, destination, speed)
root = tk.Tk()
canvas = tk.Canvas(root, width=400, height=400)
canvas.pack()
background = tk.PhotoImage(file="Images/scanner-bar.png")
item1 = canvas.create_image(0,0, image=background, anchor=tk.NW)
move_object(canvas, item1, (0, 180), 2)
move_object(canvas, item1, (0, 0), 2)
root.mainloop()