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
| from Tkinter import*
from random import randrange
def drawline():
"Tracé d'une ligne dans le canevas can1"
global x1,y1, x2,y2, cou1#FF3434
can1.create_line(x1,y1,x2,y2,width=2,fill=cou1)
#modification des coordonnées pour la ligne suivante :
y2,y1 = y2+10 , y1-10
def changecolor():
"changement aléatoire de la couleur du tracé"
global cou1
pa1=['purple','cyan','maroon','green','red','blue','orange','yellow']
c = randrange (8)
cou1
#---------------Pgm principal---------
#les variables suivantes seront utilisées de manière globale :
x1,y1, x2,y2,=10,190,190,10
cou1 = 'dark green'
#création du widget principal ("maitre") :
fen1 = Tk()
# création du widget "esclave":
can1 = Canvas (fen1,bg='dark green', height=200, width=200)
can1.pack(side=LEFT)
bou1= Button (fen1,text='Quitter',command=fen1.quit)
bou1.pack(side=BOTTOM)
bou2 = Button(fen1,text='Tracer une ligne',command-drawline)
bou2.pack()
bou3 = Button (fen1,text ='Autre couleur' ,command=changecolor)
bou3.pack()
fen1.mainloop()
fen1.destroy() |
Partager