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