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
| from Tkinter import *
from random import *
def on_clic(event):
global cpt, match
cpt += 1
items = p.find_withtag('current')
if items:
match += 1
p.delete('cible')
cible(50)
score.config(text="%d/%d" % (match, cpt))
def cercle(x, y, r, coul):
p.create_oval(x-r, y-r, x+r, y+r, fill=coul, tag='cible')
def cible(taille):
x = randrange(60, 750)
y = randrange(60, 450)
cercle(x, y, taille, 'black')
cercle(x, y, taille*3/4, 'blue')
cercle(x, y, taille*2/4, 'red')
cercle(x, y, taille*1/4, 'yellow')
cpt = 0
match = 0
fen1 = Tk()
p = Canvas(fen1, width='800', height='500')
p.pack()
score = Label(fen1, text="0/0")
score.pack()
Button(fen1, text="Quitter", command=fen1.destroy).pack()
p.bind("<Button-1>", on_clic)
cible(50)
fen1.mainloop() |
Partager