convertisseur sujet 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
820 B

import tkinter as tk
def conversion():
temperature = float(entree.get())
if choix_conversion.get() == "°F -> °C":
resultat = (temperature - 32) * 5/9
label_resultat.config(text=f"{resultat:.2f} °C")
else:
resultat = (temperature * 9/5) + 32
label_resultat.config(text=f"{resultat:.2f} °F")
fenetre = tk.Tk()
fenetre.title("Conversion température")
entree = tk.Entry(fenetre)
entree.pack()
choix_conversion = tk.StringVar()
choix_conversion.set("°F -> °C")
menu_conversion = tk.OptionMenu(fenetre, choix_conversion, "°F -> °C", "°C -> °F")
menu_conversion.pack()
bouton_convertir = tk.Button(fenetre, text="Convertir", command=conversion)
bouton_convertir.pack()
label_resultat = tk.Label(fenetre, text="Résultat :")
label_resultat.pack()
fenetre.mainloop()