Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_traffic__signal.py
- import Tkinter
- w, h = 800, 600
- canvas = Tkinter.Canvas(width=w, height=h)
- canvas.pack()
- canvas.create_rectangle(w/2 - 50, 150, w/2 + 50, 450, fill='black' )
- while True:
- canvas.create_oval(w/2 - 45, 155, w/2 + 45, 245, fill='red', tag='redLight')
- for i in range(10):
- canvas.create_text(w/2, 200, text=str(9-i), fill='white', tag='red', font='Calibri, 30')
- canvas.update()
- canvas.after(1000)
- canvas.delete('red')
- canvas.delete('redLight')
- canvas.create_oval(w/2 - 45, 345, w/2 + 45, 435, fill='green', tag='greenLight')
- for i in range(10):
- if i < 8:
- canvas.create_text(w/2, 390, text=str(7-i), fill='white', tag='green', font='Calibri, 30')
- else:
- canvas.create_oval(w/2 - 45, 250, w/2 + 45, 340, fill='orange', tag='orangeLight')
- canvas.delete('greenLight')
- canvas.after(1000)
- canvas.update()
- canvas.delete('green')
- canvas.update()
- canvas.after(1000)
- canvas.delete('orangeLight')
- Tkinter.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement