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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| from tkinter import *
import time
class ampoules:
def __init__(self, nom_can, pos_amp_x, pos_amp_y, taille):
print (pos_amp_x, " ", pos_amp_y)
self.ampoule = nom_can.create_oval(pos_amp_x, pos_amp_y, pos_amp_x+taille, pos_amp_y+taille, width=2, fill='grey')
def allume_lamp(self, nom_can):
nom_can.itemconfigure(self.ampoule, fill='red')
def etteind_lamp(self, nom_can):
nom_can.itemconfigure(self.ampoule, fill='grey')
class feux:
def __init__(self, nom_can, pos_feux_x, pos_feux_y, taille, ecart):
self.ampoule1 = ampoules(nom_can, pos_feux_x, pos_feux_y, taille)
pos_feux_y = (pos_feux_y+taille+ecart)
self.ampoule2 = ampoules(nom_can, pos_feux_x, pos_feux_y, taille)
def allume_feux(self, nom_can):
self.ampoule1.allume_lamp(can1)
self.ampoule2.allume_lamp(can1)
def etteind_feux(self, nom_can):
self.ampoule1.etteind_lamp(can1)
self.ampoule2.etteind_lamp(can1)
class panneau_feux:
def __init__(self, nom_can, pos_panneau_x, pos_panneau_y):
self.taille = 60
self.ecart = 20
self.feux1 = feux(nom_can, pos_panneau_x, pos_panneau_y, self.taille, self.ecart)
pos_panneau_x = (pos_panneau_x + self.taille+self.ecart)
self.feux2 = feux(nom_can, pos_panneau_x, pos_panneau_y, self.taille, self.ecart)
pos_panneau_x = (pos_panneau_x + self.taille + self.ecart)
self.feux3 = feux(nom_can, pos_panneau_x, pos_panneau_y, self.taille, self.ecart)
pos_panneau_x = (pos_panneau_x + self.taille + self.ecart)
self.feux4 = feux(nom_can, pos_panneau_x, pos_panneau_y, self.taille, self.ecart)
pos_panneau_x = (pos_panneau_x + self.taille + self.ecart)
self.feux5 = feux(nom_can, pos_panneau_x, pos_panneau_y, self.taille, self.ecart)
def allume_panneau(self, nom_can):
pass
def etteind_panneau(self, nom_can):
self.feux1.etteind_feux(can1)
self.feux2.etteind_feux(can1)
self.feux3.etteind_feux(can1)
self.feux4.etteind_feux(can1)
self.feux5.etteind_feux(can1)
def demarre_course(self):
time.sleep(3)
self.feux1.allume_feux(can1)
can1.update()
time.sleep(1)
self.feux2.allume_feux(can1)
can1.update()
time.sleep(1)
self.feux3.allume_feux(can1)
can1.update()
time.sleep(1)
self.feux4.allume_feux(can1)
can1.update()
time.sleep(1)
self.feux5.allume_feux(can1)
can1.update()
time.sleep(1)
self.etteind_panneau(can1)
can1.update()
time.sleep(1)
window = Tk()
window.title("Feux de départ")
window.geometry("480x360")
window.config(background="#41B77F")
can1 = Canvas(window, bg='dark grey', height=330, width=440)
can1.pack(expand="YES")
panneau1 = panneau_feux(can1, 30, 30)
can1.update()
panneau1.demarre_course()
window.mainloop() |