Bonjour à tous

Je ne trouve pas ce qui ne va pas.

Je souhaite créer une classe feux avec 3 méthodes: le constructeur , l'allumer rouge, l'allumer gris.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from tkinter import *
 
class feux:
    def __init__(self, nom_can, pos_x, pos_y, taille_x, taille_y):
        nom_can.create_oval(pos_x, pos_y, pos_x + taille_x, pos_y + taille_y, width=2, fill='grey')
 
    def allume_rouge(self, nom_can):
        nom_can.itemconfigure(self, fill='red')
 
window = Tk()
 
can1 = Canvas(window, bg='dark grey', height=330, width=400)
can1.pack(expand="YES")
 
feux1 = feux(can1, 30, 90, 50, 50)
feux1.allume_rouge(can1)
 
can1.update()
window.update()
 
window.mainloop()