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.

37 lines
1.1 KiB

import tkinter as tk
def conversion_km_to_mph():
try:
vitesse_km = float(entry.get())
vitesse_mph = vitesse_km * 0.621371
label_result.config(text= f"Vitesse en mph : {vitesse_mph:.2f} mph")
except ValueError:
label_result.config(text= "Veuillez entree une valeur valide.")
def conversion_mph_to_km():
try:
vitesse_mph = float(entry.get())
vitesse_km = vitesse_mph / 0.621371
label_result.config(text= f"Vitesse en km/h : {vitesse_km:.2f} km/h")
except ValueError:
label_result.config(text= "Veuillez entrer une valeur valide.")
root = tk.Tk()
root.title("Convertisseur de vitesse")
entry_label = tk.Label(root,text="Entrer la vitesse:")
entry_label.pack(pady=10)
entry = tk.Entry(root)
entry.pack(pady=10)
Button_conversion_km = tk.Button(root, text="conversion km/h -> mph", command = conversion_km_to_mph)
Button_conversion_km.pack(pady=5)
Button_conversion_mph = tk.Button(root,text="conversion mph -> km/h", command = conversion_mph_to_km)
Button_conversion_mph.pack(pady=5)
label_result = tk.Label(root, text="Résultat:")
label_result.pack(pady=20)
root.mainloop()