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
|
#Importation des différentes bibliothèques Python
from tkinter import*
import random
from random import randrange
import time
def lancer_chrono():
boutongo.destroy
global depart,flag
flag=1
depart = time.time()
top_horloge()
def top_horloge():
global depart,flag
y=time.time()-depart
secondes = time.localtime(y)[5]
if flag :
message.configure(text = "%i sec " %(secondes))
root.after(1000,top_horloge)
#Création de la fenêtre de jeu
root = Tk ()
root.configure (bg='#ffffff')
root.geometry ("1366x768+10+10")
root.wm_state(newstate="zoomed")
root.title ("Cliques sur la patate")
#Création du bouton pour quitter le jeu
bouton = Button(root, text='Quitter le jeu', command = root.destroy)
bouton.configure (bg = 'grey')
bouton.place(x=1250,y=5)
#Button(root,text='GO !',command=lancer_chrono).grid(row=2)
#Création du titre du jeu
titre = Label(root, text="Attrapes la patate !")
titre.place (x=375, y=5)
titre.configure (bg='#ffffff')
titre.config (font=('Comic sans ms',50,'bold'))
titre.config (fg='red')
#Création de la patate !
can=Canvas(root,width=160,height=160,bg='white')
photo=PhotoImage(file='patate.gif')
item = can.create_image(80,80,image=photo)
can.pack()
boutongo= Button(root,text='JOUER',command=lancer_chrono)
boutongo.configure(font=('Comic sans MS',20))
boutongo.config(fg='blue')
boutongo.config(bg='red')
boutongo.place(x=630,y=350)
#boutongo=Button(root,boutongo.destroy,boutongo=None)
#VARIABLES
x=500
y=300
randomx = random.randint(1,10)
randomy = random.randint(1,10)
plusx=True
plusy=True
#Boucle de déplacement de la patate
message = Label(root,font=('sans', 20, 'bold'),text="Chrono prêt")
message.grid(row=1)
while(1):
randomx = random.randint(1,10)
randomy = random.randint(1,10)
x=x+randomx if plusx else x-randomx
y=y+randomy if plusy else y-randomy
plusx=plusx if x>0 and x<1200 else not plusx
plusy=plusy if y>0 and y<550 else not plusy
can.place(x=x,y=y)
root.update()
root.mainloop () |
Partager