Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Imports the required libraries
- from time import sleep
- from tkinter import *
- #This procedure manages which light order is currently being displayed
- def loop_lights():
- red=["red","white","white"]
- red_yellow=["red","yellow","white"]
- yellow=["white","yellow","white"]
- green=["white","white","green"]
- off=["white","white","white"]
- arrangement_order=[red,red_yellow,yellow,green,off]
- current_light_order = 0
- while True:
- if current_light_order > 4:
- current_light_order = 0
- else:
- draw_lights(arrangement_order[current_light_order])
- current_light_order += 1
- sleep(2)
- #This procedure actually draws the lights when asked to by the previous procedure
- def draw_lights(light_order):
- canvas.delete("all")
- canvas.create_oval(5,5,145,145,fill=light_order[0])
- canvas.create_oval(5,150,145,295,fill=light_order[1])
- canvas.create_oval(5,300,145,445,fill=light_order[2])
- canvas.update()
- #This code manages the creation of the GUI
- main_window = Tk()
- button_start = Button(main_window, text="Start!", command=loop_lights)
- canvas = Canvas(main_window, width=150, height=450)
- button_start.pack()
- canvas.pack()
- main_window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment