Types de données en Python - LMPT
Types de données en Python - LMPT
Types de données en Python - LMPT
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Troisième exemple<br />
from tkinter import *<br />
<strong>de</strong>f cercle(can, x, y, r):<br />
can.create_oval(x-r,y-r,x+r,y+r)<br />
class Application(Tk):<br />
<strong>de</strong>f __init__(self):<br />
Tk.__init__(self)<br />
self.can=Canvas(self, width=475, height=130, bg=’white’)<br />
self.can.pack(si<strong>de</strong>=TOP, padx=5, pady=5)<br />
Button(self, text="Train", command=self.<strong>de</strong>ssine).pack(si<strong>de</strong>=LEFT)<br />
Button(self, text="Hello", command=self.coucou).pack(si<strong>de</strong>=LEFT)<br />
<strong>de</strong>f <strong>de</strong>ssine(self):<br />
self.w1=Wagon(self.can, 10, 30)<br />
self.w2=Wagon(self.can, 130, 30)<br />
self.w3=Wagon(self.can, 250, 30)<br />
self.w4=Wagon(self.can, 370, 30)<br />
<strong>de</strong>f coucou(self):<br />
self.w1.perso(3)<br />
self.w1.perso(1)<br />
self.w1.perso(2)<br />
self.w1.perso(1)<br />
class Wagon(object):<br />
<strong>de</strong>f __init__(self, canev, x,y):<br />
self.canev, self.x, self.y = canev, x, y<br />
canev.create_rectangle(x,y,x+95,y+60)<br />
for xf in range(x+5,x+90,30):<br />
canev.create_rectangle(xf,y+5,xf+25,y+40)<br />
cercle(canev, x+18, y+73, 12)<br />
cercle(canev, x+77, y+73, 12)<br />
<strong>de</strong>f perso(self, f<strong>en</strong>):<br />
xf = self.x + f<strong>en</strong>*30 - 12<br />
yf = self.y + 25<br />
cercle(self.canev, xf, yf, 10)<br />
cercle(self.canev, xf-5, yf-3, 2)<br />
cercle(self.canev, xf+5, yf-3, 2)<br />
cercle(self.canev, xf, yf+5, 3)<br />
app = Application()<br />
app.mainloop()