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.
34 lines
1.0 KiB
34 lines
1.0 KiB
import tkinter as tk
|
|
|
|
def conversion_FC():
|
|
try:
|
|
fahrenheit = float(entry_temp.get())
|
|
celsius = (fahrenheit - 32) * 5 / 9
|
|
label_result.config(text=f"{celsius:.2f} °C")
|
|
except ValueError:
|
|
label_result.config(text="Erreur : Entrez un nombre valide")
|
|
|
|
def conversion_CF():
|
|
try:
|
|
celsius = float(entry_temp.get())
|
|
fahrenheit = (celsius * 9 / 5) + 32
|
|
label_result.config(text=f"{fahrenheit:.2f} °F")
|
|
except ValueError:
|
|
label_result.config(text="Erreur : Entrez un nombre valide")
|
|
|
|
root = tk.Tk()
|
|
root.title("Convertisseur de Température")
|
|
|
|
entry_temp = tk.Entry(root)
|
|
entry_temp.pack(padx=10, pady=10)
|
|
|
|
button_conversion_FC = tk.Button(root, text="Convertir en °C", command=conversion_FC)
|
|
button_conversion_FC.pack(padx=10, pady=5)
|
|
|
|
button_conversion_CF = tk.Button(root, text="Convertir en °F", command=conversion_CF)
|
|
button_conversion_CF.pack(padx=10, pady=5)
|
|
|
|
label_result = tk.Label(root, text="Résultat", font=("Arial", 14))
|
|
label_result.pack(padx=10, pady=20)
|
|
|
|
root.mainloop()
|