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
| # -*- coding:Utf-8 -*-
#
print("Trouvez le(s) martien(s) et",
"cliquez dessus.")
print("Attention, il(s) peut(vent) être partout!")
print("")
print("Tapez sur [Entrée] pour commencer...")
r=input("")
from tkinter import *
from random import randrange
global nomfichier
nomfichier='perseverance.gif'
#détermine nombre maximum de martiens
global maxclic
maxclic=randrange(7)
#initialise les clics
global nbclic
nbclic=0
def reveil(event):
global nbclic
global maxclic
global nomfichier
#calcule les clics inférieurs au maximum
if nbclic<maxclic:
nbclic=nbclic+1
#affiche nombre martiens trouvés
texte=Label(fen,text="Vous avez trouvé "+\
str(nbclic)+" martiens.",fg="white",bg="blue")
texte.grid(row=3,column=1)
return(nomfichier)
#change image
can.delete(ALL)
nomfichier='reveil_brutal.gif'
photo2=PhotoImage(file='reveil_brutal.gif')
#item.remove : l'instruction miraculeuse!!!
#cette instruction peut afficher une exception (erreur)
#dans le terminal mais ne provoque pas l'arrêt du
#programme et sans elle l'image ne saurait changer!
item.remove=can.create_image(500,281,image=photo2)
return(nomfichier)
fen=Tk()
fen.title("Mission Mars 2020")
#boutton de sortie
b1=Button(fen,text="Quitter",command=fen.quit)
#affichage image initiale
can=Canvas(fen,width=1000,height=563)
if nomfichier=='perseverance.gif':
photo=PhotoImage(file='perseverance.gif')
item=can.create_image(500,281,image=photo)
nomfichier=""
#contrôle souris
can.bind("<Button-1>",reveil)
#nombre martiens à zéro
if nbclic==0:
texte=Label(fen,text="Vous avez trouvé "+\
str(nbclic)+" martiens.",fg="white",bg="blue")
#disposition sur écran
can.grid(row=1,column=1,padx=10,pady=10,rowspan=2)
b1.grid(row=2,column=2,sticky=S)
texte.grid(row=3,column=1)
fen.mainloop()
fen.destroy()
exit() |