Advertisement
here2share

# Tk_traffic__signal.py

Apr 15th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. # Tk_traffic__signal.py
  2.  
  3. import Tkinter
  4. w, h = 800, 600
  5. canvas = Tkinter.Canvas(width=w, height=h)
  6. canvas.pack()
  7.  
  8. canvas.create_rectangle(w/2 - 50, 150, w/2 + 50, 450, fill='black' )
  9.  
  10. while True:
  11.     canvas.create_oval(w/2 - 45, 155, w/2 + 45, 245, fill='red', tag='redLight')
  12.     for i in range(10):
  13.         canvas.create_text(w/2, 200, text=str(9-i), fill='white', tag='red', font='Calibri, 30')
  14.         canvas.update()
  15.         canvas.after(1000)
  16.         canvas.delete('red')
  17.     canvas.delete('redLight')
  18.            
  19.     canvas.create_oval(w/2 - 45, 345, w/2 + 45, 435, fill='green', tag='greenLight')
  20.     for i in range(10):
  21.         if i < 8:
  22.             canvas.create_text(w/2, 390, text=str(7-i), fill='white', tag='green', font='Calibri, 30')
  23.         else:
  24.             canvas.create_oval(w/2 - 45, 250, w/2 + 45, 340, fill='orange', tag='orangeLight')
  25.             canvas.delete('greenLight')
  26.         canvas.after(1000)
  27.         canvas.update()
  28.         canvas.delete('green')
  29.  
  30.     canvas.update()
  31.     canvas.after(1000)
  32.     canvas.delete('orangeLight')
  33.    
  34. Tkinter.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement