J'ai ce petit programme ou il s'agit juste de fermer la bouche d'un visage:

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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
 
from tkinter import *
 
def cercle(can, x, y, r):
    "dessin d'un cercle de rayon <r> en <x,y> dans le canevas <can>"
    can.create_oval(x-r, y-r, x+r, y+r)
 
class Application(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.can= Canvas(self, width=400, height=400, bg='white')
        self.can.pack(side=TOP, padx=5, pady=5)
        self.v1 = Visage(self.can,200, 200)
        Button(self, text="Fermer", command=self.v1.fermer).pack(side =LEFT)
        Button(self, text="Ouvir", command=self.v1.ouvrir).pack(side =LEFT)
 
class Visage(object):
    def __init__(self, canev, x, y):
        self.canev, self.x, self.y = canev, x, y
        cercle(self.canev, self.x, self.y, 30)
        cercle(self.canev,self.x-15,self.y-15,10)
        cercle(self.canev,self.x+15,self.y-15,10)
        self.bouche=cercle(self.canev,self.x,self.y+15,10)
 
 
    def fermer(self):
        self.canev.delete(self.bouche) 
        self.bouche = self.canev.create_line(self.x-15, self.y+15, self.x+15, self.y+15)
 
    def ouvrir(self):
        self.canev.delete(self.bouche)
        self.bouche=cercle(self.canev,self.x,self.y+15,10)
 
app = Application()
app.mainloop()
Comment faire pour supprimer l'attribut self.bouche une fois qu'on actionne fermer?

Merci pour votre aide

Roman