|
1 |
| -#Projet jeu des couleurs |
2 |
| -#L1 MIASHS TD02 |
3 |
| -#Pentinat Antoine, Négrier Amélie, Tairou Iswat, Auclerc Emre, Huguen Marine, Rafiq Loubna |
| 1 | +# Projet jeu des couleurs |
| 2 | +# L1 MIASHS TD02 |
| 3 | +# Pentinat Antoine, Négrier Amélie, Tairou Iswat, Auclerc Emre, Huguen Marine, Rafiq Loubna |
4 | 4 |
|
5 |
| -#création de la fenetre graphique |
6 |
| -from tkinter import * |
| 5 | +# création de la fenetre graphique |
7 | 6 | import tkinter as tk
|
8 | 7 | import random as rd
|
9 |
| -import time |
10 |
| -from turtle import * |
11 | 8 |
|
12 | 9 |
|
13 |
| -racine = Tk() |
14 |
| -racine.title("Jeu de couleurs") |
15 |
| -racine.geometry("900x300") |
16 |
| -racine.config(background="azure2") |
17 |
| -canvas=Canvas(racine, width=300, height= 900, bg="azure2") |
18 |
| -canvas2=Canvas(racine, width=300, height= 900, bg="azure2") |
| 10 | +compteur = 30 |
| 11 | +score = 0 |
| 12 | +demarrer = False |
| 13 | +# couleurs = ['deep sky blue','firebrick1','spring green2','Gold','DeepPink2','chocolate1','white'] |
| 14 | +couleurs = ["blue", "red", "green", "yellow", "pink", "orange", "white"] |
| 15 | +mots = ['Bleu', 'Rouge', 'Vert', 'Jaune', 'Rose', 'Orange', 'Blanc', 'Violet', 'Noir', 'Marron', 'Gris', 'Beige'] |
| 16 | + |
19 | 17 |
|
20 | 18 | def réinitialiser():
|
21 | 19 | """Fonction qui remet le score à 0 et qui remet le compte à rebours à 30 secondes"""
|
22 |
| - pass |
| 20 | + global demarrer, score, compteur |
| 21 | + compteur = 30 |
| 22 | + compteur_lbl['text'] = str(compteur) |
| 23 | + score = 0 |
| 24 | + label_score["text"] = "Score : " + str(score) |
| 25 | + demarrer = False |
| 26 | + canvas.after_cancel(repeat) |
| 27 | + |
23 | 28 |
|
24 |
| -#ajout des fonctions |
| 29 | +# ajout des fonctions |
25 | 30 | def incremente():
|
26 | 31 | """Fonction qui génère un compte à rebours de 30 secondes"""
|
27 |
| - global compteur |
28 |
| - if compteur > 0 : |
29 |
| - compteur -=1 |
| 32 | + global compteur, demarrer, repeat |
| 33 | + demarrer = True |
| 34 | + if compteur > 0: |
| 35 | + compteur -= 1 |
30 | 36 | compteur_lbl['text'] = str(compteur)
|
31 |
| - canvas.after(1000, incremente) |
32 |
| - return compteur |
| 37 | + repeat = canvas.after(1000, incremente) |
| 38 | + else: |
| 39 | + demarrer = False |
33 | 40 |
|
34 | 41 |
|
35 |
| - |
36 |
| -compteur = 30 |
37 |
| -compteur_lbl = tk.Label(canvas, text=str(compteur), font=("", 16)) |
38 |
| -compteur_lbl.pack() |
39 |
| -score = 0 |
40 |
| - |
41 |
| -def changement(str, couleur): |
| 42 | +def changement(color): |
42 | 43 | """fonction qui permet de changer aléatoirement la couleur et le mot (du label_title)"""
|
43 |
| - global label_title |
44 |
| - global score |
45 |
| - label_title["text"]= str |
46 |
| - label_title["fg"]= couleur |
47 |
| - score+=1 |
48 |
| - |
49 |
| -#Apparition du mot du milieu |
50 |
| -couleurs = ['deep sky blue','firebrick1','spring green2','Gold','DeepPink2','chocolate1','white'] |
51 |
| -mots = ['Bleu','Rouge','Vert','Jaune','Rose','Orange','Blanc','Violet','Noir','Marron','Gris','Beige'] |
52 |
| -label_title = Label(canvas, text=rd.choice(mots), font=("Cassia",40), fg=rd.choice(couleurs), bg='azure2') |
53 |
| -label_title.pack() |
| 44 | + global label_title, score |
| 45 | + if demarrer is True: |
| 46 | + if label_title["fg"] == color: |
| 47 | + score += 1 |
| 48 | + label_score["text"] = "Score : " + str(score) |
| 49 | + label_title["text"] = rd.choice(mots) |
| 50 | + label_title["fg"] = rd.choice(couleurs) |
| 51 | + print(label_title["fg"], color) |
| 52 | + |
54 | 53 |
|
55 |
| - |
| 54 | +racine = tk.Tk() |
| 55 | +racine.title("Jeu de couleurs") |
| 56 | +racine.geometry("1130x300") |
| 57 | +racine.config(background="azure2") |
| 58 | +canvas = tk.Canvas(racine, width=300, height=900, bg="azure2") |
| 59 | +canvas2 = tk.Canvas(racine, width=300, height=900, bg="azure2") |
56 | 60 |
|
57 |
| -label_text = Label(canvas, text="Tapez la couleur des mots et pas le texte des mots !", bg="azure2", font=("Cassia", 20)) |
58 |
| -label_score = Label(canvas, text="Score : " + str(score), bg ="azure2", font=("Cassia", 18)) |
59 | 61 |
|
| 62 | +# Apparition du mot du milieu |
| 63 | +compteur_lbl = tk.Label(canvas, text=str(compteur), font=("", 16)) |
| 64 | +compteur_lbl.pack() |
60 | 65 |
|
| 66 | +label_title = tk.Label(canvas, text=rd.choice(mots), font=("Cassia", 40), fg=rd.choice(couleurs), bg='azure2') |
| 67 | +label_title.pack() |
61 | 68 |
|
62 |
| -#ajout des boutons |
| 69 | +label_text = tk.Label(canvas, text="Tapez la couleur des mots et pas le texte des mots !", bg="azure2", font=("Cassia", 20)) |
| 70 | +label_score = tk.Label(canvas, text="Score : " + str(score), bg="azure2", font=("Cassia", 18)) |
63 | 71 |
|
64 |
| -first_button = Button(canvas, text="Démarrer", command=incremente) |
65 |
| -second_button = Button(canvas, text="réinitialiser", command = réinitialiser) |
66 |
| -third_button = Button(canvas, text='Bleu', bg=couleurs[0], command= lambda : changement(rd.choice(mots), rd.choice(couleurs))) |
67 |
| -fourth_button = Button(canvas, text='Rouge', bg=couleurs[1], command = lambda: changement(rd.choice(mots), rd.choice(couleurs))) |
68 |
| -fifth_button = Button(canvas, text='Vert', bg=couleurs[2], command= lambda : changement(rd.choice(mots), rd.choice(couleurs))) |
69 |
| -sixth_button = Button(canvas, text='Jaune', bg=couleurs[3], command= lambda : changement(rd.choice(mots), rd.choice(couleurs))) |
70 |
| -seventh_button = Button(canvas, text='Rose', bg=couleurs[4], command= lambda : changement(rd.choice(mots), rd.choice(couleurs))) |
71 |
| -eighth_button = Button(canvas, text='Orange', bg=couleurs[5], command= lambda : changement(rd.choice(mots), rd.choice(couleurs))) |
72 |
| -ninth_button = Button(canvas, text='Blanc', bg=couleurs[6], command= lambda : changement(rd.choice(mots), rd.choice(couleurs))) |
73 | 72 |
|
| 73 | +# ajout des boutons |
| 74 | +first_button = tk.Button(canvas, text="Démarrer", command=incremente) |
| 75 | +second_button = tk.Button(canvas, text="réinitialiser", command=réinitialiser) |
| 76 | +third_button = tk.Button(canvas, text='Bleu', bg=couleurs[0], command=lambda: changement("blue")) |
| 77 | +fourth_button = tk.Button(canvas, text='Rouge', bg=couleurs[1], command=lambda: changement("red")) |
| 78 | +fifth_button = tk.Button(canvas, text='Vert', bg=couleurs[2], command=lambda: changement("green")) |
| 79 | +sixth_button = tk.Button(canvas, text='Jaune', bg=couleurs[3], command=lambda: changement("yellow")) |
| 80 | +seventh_button = tk.Button(canvas, text='Rose', bg=couleurs[4], command=lambda: changement("pink")) |
| 81 | +eighth_button = tk.Button(canvas, text='Orange', bg=couleurs[5], command=lambda: changement("orange")) |
| 82 | +ninth_button = tk.Button(canvas, text='Blanc', bg=couleurs[6], command=lambda: changement("white")) |
74 | 83 |
|
75 | 84 |
|
76 |
| -#Affichage |
| 85 | +# Affichage |
77 | 86 | label_text.pack()
|
78 | 87 | label_score.pack()
|
79 |
| -first_button.pack(side =LEFT , pady =50) |
80 |
| -second_button.pack(side =RIGHT, pady =50) |
81 |
| -third_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
82 |
| -fourth_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
83 |
| -fifth_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
84 |
| -sixth_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
85 |
| -seventh_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
86 |
| -eighth_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
87 |
| -ninth_button.pack(side=LEFT, padx=15, ipadx=20, ipady=10) |
| 88 | +first_button.pack(side=tk.LEFT, pady=50) |
| 89 | +second_button.pack(side=tk.RIGHT, pady=50) |
| 90 | +third_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
| 91 | +fourth_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
| 92 | +fifth_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
| 93 | +sixth_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
| 94 | +seventh_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
| 95 | +eighth_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
| 96 | +ninth_button.pack(side=tk.LEFT, padx=15, ipadx=20, ipady=10) |
88 | 97 | canvas.pack()
|
89 | 98 |
|
90 | 99 |
|
91 |
| - |
92 |
| - |
93 | 100 | racine.mainloop()
|
0 commit comments