1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Python-Traffic Light

  1. Oct 20, 2012 #1
    Trying to create a traffic light in python, simply by creating a rectangle and circles in a canvas. The lights change from green to yellow, yellow to red, and red to green. Only one color can be on at a time. Start the animation with the green light on. The program waits for two seconds before changing from one color to another.

    from Tkinter import *

    class TrafficLights(Frame):

    def __init__(self):
    """Sets up the window and widgets."""

    self.master.title("Traffic Lights")
    # create a canvas and place in this frame
    self.canvas = Canvas(self, width = 300, height = 400,
    bg = "white")
    self.canvas.grid(row = 0, column = 0)
    self.canvas.create_rectangle(100, 50, 200, 350)

    self.canvas.create_oval(100, 50, 200, 150, fill=x)
    self.canvas.create_oval(100, 150, 200, 250, fill=y)
    self.canvas.create_oval(100, 250, 200, 350, fill=z)

    def main():


    That is what I have so far and am not too sure on the best way to go from here. I'm pretty sure i need to use after() and update() but I just need assistance with setting up the animation to fill the circles
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted