commit
4db49b3329
1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||
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() |
Loading…
Reference in new issue