-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholympic-cercles-tkinter.py
More file actions
50 lines (45 loc) · 1.72 KB
/
Copy patholympic-cercles-tkinter.py
File metadata and controls
50 lines (45 loc) · 1.72 KB
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
# dessine des trais de differentes couleurs
from tkinter import *
# --- définition des fonctions gestionnaires d'événements : ---
def drawbluecercle():
"Tracé d'un cercle dans le canevas can1"
global x1, y1, x2, y2
can1.create_oval(x1,y1,x2, y2,width=4,outline='blue')
def drawredcercle():
global x5, y5 ,x6 ,y6
can1.create_oval(x5,y5,x6,y6,width=4,outline='red')
def drawblackcercle():
global x3, y3, x4, y4
can1.create_oval(x3,y3,x4,y4,width=4,outline='black')
def draworangecercle():
global x7, y7, x8, y8
can1.create_oval(x7,y7,x8,y8,width=4,outline='orange')
def drawgreencercle():
global x9, y9, x10, y10
can1.create_oval(x9,y9,x10,y10,width=4,outline='green')
#------ Programme principal -------
# les variables suivantes seront utilisées de manière globale :
x1, y1, x2, y2 = 200, 100, 50, 250 # coordonnées du cercle
x3, y3, x4,y4 = 360, 100, 210, 250 # coord du cercle
x5, y5, x6, y6 = 520, 100, 370, 250
x7, y7, x8, y8 = 280, 200, 130, 350
x9, y9, x10, y10 = 440, 200, 290, 350
# Création du widget principal ("maître") :
fen1 = Tk()
# création des widgets "esclaves" :
can1 = Canvas(fen1,bg='white',height=500,width=600)
can1.pack(side=LEFT)
bou1 = Button(fen1,text='Quitter',command=fen1.quit)
bou1.pack(side=BOTTOM)
bou2 = Button(fen1,text='Anneau bleu',command=drawbluecercle)
bou2.pack()
bou3 = Button(fen1,text='Anneau noir',command=drawblackcercle)
bou3.pack()
bou4 = Button(fen1,text='Anneau rouge',command=drawredcercle)
bou4.pack()
bou5 = Button(fen1,text='Anneau jaune',command=draworangecercle)
bou5.pack()
bou6 = Button(fen1,text='Anneau vert',command=drawgreencercle)
bou6.pack()
fen1.mainloop() # démarrage du réceptionnaire d'événements
fen1.destroy() # destruction (fermeture) de la fenêtre