Это мой код, пожалуйста, помогите

from tkinter import *
root = Tk()
def update_shapes(val):
# Move the oval based on the scale value
offset = int(val)
C.coords(oval, 230 + offset, 45, 270 + offset, 85)
# Start the return animation after a delay
root.after(1500, return_to_origin)`your text`
def return_to_origin():
# Animate the oval back to its original position
current_coords = C.coords(oval)
start_x = 230
end_x = current_coords[0] # Current x position
step = 1 if end_x > start_x else -1
if end_x != start_x:
end_x -= step
C.coords(oval, end_x, 45, end_x + 40, 85)
root.update()
root.after(10, return_to_origin) # Call again after a short delay
else:
H.set(0) # Reset the scale to zero
#root.after(200, oscillate_first_back) # Start the first oscillation segment after a delay
"""
def oscillate_first_back():
# First half of first oscillation - go back
for i in range(40):
C.move(oval, -1, 0)
root.update()
root.after(10)
root.after(10, oscillate_first_forward) # Proceed to next phase
def oscillate_first_forward():
# Second half of first oscillation - go forward
for i in range(80):
C.move(oval, 1, 0)
root.update()
root.after(10)
root.after(10, oscillate_second_back) # Proceed to next phase
def oscillate_second_back():
# First half of second oscillation - go back
for i in range(20):
C.move(oval, -1, 0)
root.update()
root.after(10)
root.after(10, oscillate_second_forward) # Proceed to next phase
def oscillate_second_forward():
# Second half of second oscillation - go forward
for i in range(40):
C.move(oval, 1, 0)
root.update()
root.after(10)
root.after(10, reset_position) # Proceed to final reset
def reset_position():
# Reset the oval to the original position
C.coords(oval, 230, 45, 270, 85) # Center at original position
"""
# Create a horizontal scale
H = Scale(root, from_=-150, to=150, orient=HORIZONTAL, command=update_shapes)
H.grid(row=0, column=0)
# Create a canvas
C = Canvas(root, bg="#92dadd", height=230, width=500)
# Draw shapes
oval = C.create_oval(230, 45, 270, 85, fill="white", outline="")
line = C.create_line(100, 100, 400, 100, fill="black", width=22)
rectangle = C.create_rectangle(390, 75, 420, 220, fill="black")
motor = C.create_rectangle(100, 165, 115, 100, fill="black")
C.grid(row=1, column=0)
mainloop()
Подробнее здесь: https://stackoverflow.com/questions/791 ... scillating