commit
f3b20c129d
1 changed files with 75 additions and 0 deletions
@ -0,0 +1,75 @@ |
|||
import tkinter as tk |
|||
|
|||
# Configuration de la fenêtre |
|||
screen = tk.Tk() |
|||
screen.minsize(300, 300) |
|||
screen.maxsize(300, 300) |
|||
|
|||
lst_nombre = [] |
|||
|
|||
# Différents textes présents (ou non) sur la page |
|||
#Zone d'entrée pour les nombres |
|||
welcome_txt = tk.Label(text="Veuillez entrer des nombres, pour connaitre \n la note la plus basse, la plus haute et la moyenne !") |
|||
welcome_txt.place(relx=0.5, y=70, anchor="center") |
|||
|
|||
zone_texte = tk.Entry(width = 20) |
|||
zone_texte.place(relx=0.5, rely=0.5, anchor="center") |
|||
|
|||
warning = tk.Label(text="") |
|||
warning.place(relx=0.5, rely=0.3, anchor="center") |
|||
|
|||
txt_note_min = tk.Label(text="") |
|||
txt_note_min.place(x=0, y=10) |
|||
|
|||
txt_note_max = tk.Label(text="") |
|||
txt_note_max.place(x=170, y=10) |
|||
|
|||
txt_moyenne = tk.Label(text="") |
|||
txt_moyenne.place(relx=0.5, y=40, anchor="center") |
|||
|
|||
|
|||
# Vérifie les entrées |
|||
def Verif(): |
|||
global lst_nombre |
|||
global zone_texte |
|||
# Pour être sûr que l'utilisateur ne fait pas n'importe quoi |
|||
try: |
|||
nombre = zone_texte.get() |
|||
# On part du principe que l'utilisateur ne sait pas qu'il faut utiliser des points à la place des virgules |
|||
nombre = nombre.replace("," , ".") |
|||
nombre = float(nombre) |
|||
print(nombre) |
|||
lst_nombre.append(nombre) |
|||
warning.config(text="") |
|||
except ValueError: |
|||
warning.config(text="Non") |
|||
print("Dommage !") |
|||
|
|||
# Calcule la note max, min et la moyenne |
|||
def Calcul(): |
|||
global lst_nombre |
|||
total = 0 |
|||
nombre_notes = 0 |
|||
print(lst_nombre) |
|||
lst_nombre.sort() |
|||
print(lst_nombre) |
|||
note_min = lst_nombre[0] |
|||
note_max = lst_nombre[-1] |
|||
for i in range(len(lst_nombre)): |
|||
total += lst_nombre[i] |
|||
nombre_notes += 1 |
|||
moyenne = total/nombre_notes |
|||
moyenne = round(moyenne, 1) |
|||
txt_note_min.config(text=f"Note la plus basse : {note_min}") |
|||
txt_note_max.config(text=f"Note la plus haute : {note_max}") |
|||
txt_moyenne.config(text=f"Moyenne du groupe : {moyenne}") |
|||
|
|||
|
|||
# Différents bouton qui renvoie aux deux fonctions |
|||
bouton_verif = tk.Button(width = 8, height = 3, text = "Vérifier", command=Verif) |
|||
bouton_verif.place(relx=0.5, rely=0.7, anchor="center") |
|||
|
|||
bouton_calcul = tk.Button(width = 8, height = 3, text = "Calcul", command=Calcul) |
|||
bouton_calcul.place(relx=0.7, rely=0.8,) |
|||
|
|||
screen.mainloop() |
Loading…
Reference in new issue