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