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 43 44 45 46 47 48 49 50 51 52 53 54
| import tkinter as tk
class Application(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.creer_widgets()
def creer_widgets(self):
self.grid()
self.frame=tk.Frame(self, bg='#44D6B1')
self.frame.grid(row=1,column=2,padx=100,pady=100)
# Création du label
self.label = tk.Label(self.frame, text ="Saisir le montant en euros: ",bg='#44D6B1',font=("Helvetica", 20))
self.label.grid(row=2, column=2, padx=3, pady=8)
# Création du champ de saisie pour l'opération
self.entryVariable = tk.StringVar()
self.Entry = tk.Entry(self.frame,textvariable=self.entryVariable,
bg = '#44D6B1', width="20",
highlightbackground = "blue", font=("Helvetica", 14),
highlightcolor= "green")
self.Entry.grid(row=2, column=3, padx=3, pady=8)
self.Entry.focus_set()
self.Entry.bind("<Return>",self.conv_eur_francs)
# Création d'un label qui affiche le résultat
self.labelVariable = tk.StringVar()
self.label = tk.Label(self.frame,textvariable=self.labelVariable,bg='#44D6B1',
font=("Helvetica", 20))
self.label.grid(row=4,column=2,columnspan=3, padx=3, pady=10)
self.label = tk.Label(self.frame, text ="F ",bg='#44D6B1',font=("Helvetica", 20))
self.label.grid(row=4, column=3, padx=3, pady=8)
##----- Création des boutons -----##
self.bouton = tk.Button(self.frame, text='Quitter', width='30'
,bg='red',command=self.destroy)
self.bouton.grid(row=5, column=2, padx=5, pady=20)
def conv_eur_francs(self,event):
self.labelVariable.set( 'resultat = '+str (eval(self.entryVariable.get())* 6.55957))
if __name__ == "__main__":
app = Application()
app.title("Convertisseur Euros vers francs:)")
app.geometry("800x400")
app.iconbitmap("alain2.ico")
app.config(background='#44D6B1')
##----- Programme principal -----##
app.mainloop()# Boucle d'attente des événements |
Partager