I Am Making A Traffic Light With Python Turtle And At The End Of The Sequence I Want All The Lights To Blink Yellow
This is my code. All I want is for three turtles to move/blink at the same time like a broken traffic light. I can't figure out how to do it. If you want to see all of my code, le
Solution 1:
Here's a solution based on two key points: first, the turtles aren't used to draw the traffic lights, the turtles are the traffic lights; second, we use the ontimer
event in turtle to control the blinking:
from turtle import Turtle, Screen
CURSOR_SIZE = 20
def blink():
for turtle in screen.turtles():
turtle.fillcolor('yellow' if turtle.fillcolor() == 'black' else 'black')
screen.ontimer(blink, 1000)
screen = Screen()
pen1 = Turtle(shape='circle')
pen1.shapesize(80 / CURSOR_SIZE)
pen1.color('black', 'yellow')
pen1.penup()
pen1.sety(90)
pen2 = pen1.clone()
pen2.sety(0)
pen3 = pen1.clone()
pen3.sety(-90)
blink()
screen.mainloop()
Post a Comment for "I Am Making A Traffic Light With Python Turtle And At The End Of The Sequence I Want All The Lights To Blink Yellow"