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 55 56 57 58 59 60 61 62 63 64 65 66
| from Tkinter import *
from math import *
#*************Fonction calcul************************
#Création d'une fonction calcul
def calcul ():
#Récupération des variables saisie
ans=int(ans1.get())
arg_dep=float(arg_dep1.get())
itr=float(itr1.get())
#Traitament de variable
arg_x_ans=arg_dep
itr=itr/100.
#Boucle permettant de connaître la somme total au bout de X années
a=0
while a<ans:
a=a+1
arg_x_ans=arg_x_ans*itr+arg_x_ans
#Calcul du gain
gain=arg_x_ans-arg_dep
#On traite les variables pour qu'elles affichent deux chiffres
#après la virgule, puis on affiche.
if gain>=0:
gain1="Gain: %.2f " % (gain)
else:
gain1="Perte: %.2f " % (-gain)
chaine.configure(text = gain1)
arg_x_ans1="Total: %.2f " % (arg_x_ans)
chaine1.configure(text = arg_x_ans1)
#*************Programme principal************************
fenetre = Tk()
fenetre.title("Calcul des intérêts")
#Création des widget Label et Entry
txt1=Label(fenetre, text="Nombre d'années:").grid(row=1, column=1)
txt2=Label(fenetre, text='Argent au départ:').grid(row=2, column=1)
txt3=Label(fenetre, text='Intérêts (en %):').grid(row=3, column=1)
Button(fenetre,text='Calculer',command=calcul).grid(row=4 , column=1)
Button(fenetre,text='Quitter',command=fenetre.destroy).grid(row=4, column=2)
ans1=Entry(fenetre)
arg_dep1=Entry(fenetre)
itr1=Entry(fenetre)
chaine = Label(fenetre)
chaine1 = Label(fenetre)
#Mise en page à l'aide de la méthode 'grid'
ans1.grid(row=1, column=2)
arg_dep1.grid(row=2, column=2)
itr1.grid(row=3, column=2)
chaine.grid(row=5, column=2)
chaine1.grid(row=6, column=2)
#démarrage
fenetre.mainloop()
#End |
Partager