1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| from tkinter import *
def change_coul():
global c
if c ==0:
#Feu
can.create_oval(115-15,185-15,115+15,185+15,fill= coul[0])
can.create_oval(430-15,185-15,430+15,185+15,fill= coul[1])
can.create_oval(115-15,300-15,115+15,300+15,fill= coul[1])
can.create_oval(430-15,300-15,430+15,300+15,fill= coul[0])
c=1
else:
#Feu
can.create_oval(115-15,185-15,115+15,185+15,fill= coul[1])
can.create_oval(430-15,185-15,430+15,185+15,fill= coul[0])
can.create_oval(115-15,300-15,115+15,300+15,fill= coul[0])
can.create_oval(430-15,300-15,430+15,300+15,fill= coul[1])
c = 0
def rectangle(x,y,y1,x1, coul):
i = 0
while i < 8:
can.create_rectangle(x,y,x+v,y+d, fill=coul)
i+=1
x+=v*2
coul = ["red","green"]
c = 0
v = 15
d = 100
fen = Tk()
can = Canvas(fen, width = 500, height = 500, bg="silver")
# ROUTE
can.create_rectangle(150,0,400,500, fill="grey")
#PASSAGE PIETON
i = 0
while i < 8:
rectangle(160,200,20,250, "yellow")
i+=1
#Feu
can.create_oval(115-15,185-15,115+15,185+15,fill= coul[1])
can.create_oval(430-15,185-15,430+15,185+15,fill= coul[0])
can.create_oval(115-15,300-15,115+15,300+15,fill= coul[0])
can.create_oval(430-15,300-15,430+15,300+15,fill= coul[1])
Button(fen, text="feu rouge", command=change_coul).pack(side=BOTTOM)
can.pack()
fen.mainloop() |
Partager