I have been trying to bind number keys to change color turtle program, when i try to bind it in loop it only takes last color.
import turtle
colors = ('violet', 'indigo', 'blue', 'green', 'yellow', 'red', 'orange')
for i, c in enumerate(colors):
turtle.onkey(lambda: turtle.color(c), i)
turtle.listen()
turtle.mainloop()
but works if I do it separately without loop
turtle.onkey(lambda: turtle.color(colors[1]), 1)
turtle.onkey(lambda: turtle.color(colors[2]), 2)
turtle.onkey(lambda: turtle.color(colors[3]), 3)