1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
#
from Tkinter import *
def affiche(titre, reponse):
for widget in F.winfo_children():
if isinstance(widget, Toplevel):
widget.destroy()
conteneur = Toplevel(F)
conteneur.title('Résultat')
Label(conteneur, text=titre).pack()
Label(conteneur, text='Résultat: ' + str(reponse)).pack()
Button(conteneur, text='Ok', command=conteneur.destroy).pack(padx=5, pady=5)
def quelletouche(event):
global touche
touche = event
def veriftouche():
if touche.char.isdigit() or touche.keysym == "BackSpace":
return True
else:
entree.configure(validate='key', validatecommand=veriftouche)
return False
F = Tk()
Label(F,text="Convertisseur température").pack(fill=BOTH)
Label(F, text = 'Entrez la Temperature :').pack(fill=BOTH)
entree = Entry(F, justify=CENTER, validate='key', validatecommand=veriftouche)
entree.bind("<Key>", quelletouche)
entree.pack(padx=5, pady=5, fill=BOTH)
entree.focus_set()
Button(F, text='CelToFah', command=lambda: affiche('Convertion de Celsius en Fahrenheit', 9./5.*int(entree.get())+32)).pack(padx=5, pady=5, fill=BOTH)
Button(F, text='CelToKel', command=lambda: affiche('Convertion de Celsius en Kelvin', int(entree.get())+273.15)).pack(padx=5, pady=5, fill=BOTH)
Button(F, text='KelToFah', command=lambda: affiche('Convertion de Kelvin en Fahrenheit', 9./5.*(int(entree.get())-459.67))).pack(padx=5, pady=5, fill=BOTH)
Button(F, text='KelToCel', command=lambda: affiche('Convertion de Kelvin en Celsius', int(entree.get())-273.15)).pack(padx=5, pady=5, fill=BOTH)
Button(F, text='FahToCel', command=lambda: affiche('Convertion de Fahrenheit en Celsius', 5./9.*(int(entree.get())-32))).pack(padx=5, pady=5, fill=BOTH)
Button(F, text='FahToKel', command=lambda: affiche('Convertion de Fahrenheit en Kelvin', 5./9.*(int(entree.get())-32))).pack(padx=5, pady=5, fill=BOTH)
Button(F, text='Quitter', command=F.quit).pack(padx=5, pady=5, fill=BOTH)
F.mainloop() |
Partager