hi guys im stuck on my project as im new to python. im using tkinter module.
i need to create some traffic lights along the stretch of road and the vehicles should me able to stop the when it is red and should go when green lights. also they should be able to move along different roads and at different speeds.
im thus providing you with all that i have hoping to get the final outcome. thanks...
import Tkinter as tk
import time
root=tk.Tk()
root.title("Traffic Simulation")
canvas = tk.Canvas(root, width=1000, height=400, bg="#FFFFFF")
canvas.pack()
# make roads
l1=canvas.create_line(140,150,200,150,
200,150,200,50, width=5)
l2=canvas.create_line(250,150,250,50,
250,150,374,150,
374,150,374,50, width=5)
l3=canvas.create_line(424,150,424,50,
424,150,542,150,
542,150,542,50, width=5)
l4=canvas.create_line(592,150,592,50,
592,150,674,150,
674,150,674,50, width=5)
l5=canvas.create_line(724,150,724,50,
724,150,850,150, width=5)
l6=canvas.create_line(140,200,200,200,
200,200,200,300, width=5)
l7=canvas.create_line(250,200,250,300,
250,200,344,200,
344,200,344,300, width=5)
l8=canvas.create_line(394,200,394,300,
394,200,542,200,
542,200,542,300, width=5)
l9=canvas.create_line(592,200,592,300,
592,200,674,200,
674,200,674,300, width=5)
l10=canvas.create_line(724,200,724,300,
724,200,850,200, width=5)
# color roads
rect=canvas.create_rectangle(140,152,850,198, fill="#999999", outline="#999999")
rect1=canvas.create_rectangle(202,50,248,300, fill="#999999", outline="#999999")
rect2=canvas.create_rectangle(376,50,422,152, fill="#999999", outline="#999999")
rect3=canvas.create_rectangle(346,198,392,300, fill="#999999", outline="#999999")
rect4=canvas.create_rectangle(544,52,590,300, fill="#999999", outline="#999999")
rect5=canvas.create_rectangle(676,52,722,300, fill="#999999", outline="#999999")
# lines on road
l11=canvas.create_line(140,175,850,175, width=5, fill="White")
l12=canvas.create_line(225,50,225,150,248,150, width=5, fill="White")
l13=canvas.create_line(202,200,248,200, width=5, fill="White")
l14=canvas.create_line(225,200,225,300, width=5, fill="White")
l15=canvas.create_line(399,50,399,150,422,150, width=5, fill="White")
l16=canvas.create_line(346,200,392,200, width=5, fill="White")
l17=canvas.create_line(369,200,369,300, width=5, fill="White")
l18=canvas.create_line(567,50,567,150,590,150, width=5, fill="White")
l19=canvas.create_line(699,50,699,150,722,150, width=5, fill="White")
l20=canvas.create_line(544,200,590,200, width=5, fill="White")
l21=canvas.create_line(567,200,567,300, width=5, fill="White")
l22=canvas.create_line(676,200,722,200, width=5, fill="White")
l23=canvas.create_line(699,200,699,300, width=5, fill="White")
l24=canvas.create_line(200,152,200,175, width=5, fill="White")
l25=canvas.create_line(374,152,374,175, width=5, fill="White")
l26=canvas.create_line(542,152,542,175, width=5, fill="White")
l27=canvas.create_line(674,152,674,175, width=5, fill="White")
l28=canvas.create_line(724,198,724,175, width=5, fill="White")
l29=canvas.create_line(592,198,592,175, width=5, fill="White")
l30=canvas.create_line(394,198,394,175, width=5, fill="White")
l28=canvas.create_line(250,198,250,175, width=5, fill="White")
# create car
car = canvas.create_rectangle(20, 155, 40, 170, outline='blue', fill='blue')
#car=canvas.create_oval(20,155,34,169, outline='blue', fill='blue')
# move car
for x in range(200):
y= x = 5
time.sleep(0.025)
canvas.move(car, x, 0)
canvas.update()
root.mainloop()