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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| from tkinter import *
import random
import time
fenetre = Tk()
fenetre.geometry("500x600")
Fab= Frame (fenetre, width=480, height=400,bg="dark grey")
Fab.place(x=9, y=5)
Cab= Canvas(Fab, width=480, height=400, bg="dark grey")
Cab.place(x=0, y=0)
VARBALLE=0
ABN=0
Cab=Canvas(Fab, width=480,height=400, bg="dark grey", cursor="hand1")
Cab.place(x=0,y=0)
def initialisationballes():
global a
for i in range (0,500):
a = i
a=str(a)
creationballebleue()
creationballerouge()
mouvementballe()
def creationballebleue():
A= random.randint(0,450)
B=random.randint(0,450)
ballen=StringVar()
ballen="balle"+a
ballen=Cab.create_oval(A,B,A+20,B+20, fill="blue")
def creationballerouge():
global ballerouge
A=random.randint(40,300)
B=random.randint(40,400)
ballerouge=Cab.create_oval(A,B,A+20,B+20, fill="dark red")
def ABdebut():
global Cab
Cab=Canvas(Fab, width=480,height=400, bg="dark grey", cursor="hand1")
Cab.place(x=0,y=0)
initialisationballes()
def ABdebutdetruire():
Cab.destroy()
ABdebut()
def fin():
time.sleep(5)
fenetre.destroy()
def mouvementballe():
global ABN
Cab.move(ballerouge,3,3)
ABA= Cab.coords(ballerouge)
x1 = ABA[0]
y1 = ABA[1]
x2 = ABA[2]
y2 = ABA[3]
if ABN>= 5:
fin()
if x1>= 480:
ABN=ABN+1
ABdebutdetruire()
if y1>= 400:
ABN=ABN+1
ABdebutdetruire()
else:
fenetre.after(10, mouvementballe)
def Fcab(event):
print ("1")
global VARBALLE
D1= event.x
E1= event.y
ABA= Cab.coords(ballerouge)
x1 = ABA[0]
y1 = ABA[1]
x2 = ABA[2]
y2 = ABA[3]
if x1 <=D1<=x2 and y1<=E1<=y2:
VARBALLE = VARBALLE+1
ABnombre.configure(text=VARBALLE)
else:
VARBALLE=VARBALLE
ABnombre.configure(text=VARBALLE)
Cab.bind("<Button-1>", Fcab)
Babjouer= Button(fenetre, bg="dark grey", text="réinitialiser", relief=FLAT, command=ABdebut)
Babjouer.place(x=400, y=475)
ABregles= Label (fenetre, text="Touchez 20 fois la balle rouge qui se déplace!", fg="black", font="Helvetica")
ABregles.place(x=10, y=430)
ABregles2= Label (fenetre, text="Attention, la vitesse augmente", fg="black", font="Helvetica")
ABregles2.place(x=10, y=460)
ABregles3= Label (fenetre, text="Cliquez sur JOUER pour commencer", fg="black", font="Helvetica")
ABregles3.place(x=10, y=490)
ABregles4= Label (fenetre, text="Vous avez touché la balle fois", fg="black", font="Helvetica")
ABregles4.place(x=10, y=520)
ABnombre= Label (fenetre, text="0", fg="black", font="Helvetica")
ABnombre.place(x=187, y=520)
VARBALLE=0
VARBALLE=int(VARBALLE) |
Partager