Calcular a Taxa de Juro Composto usando tkinter

import tkinter

class compintapp_tk(tkinter.Tk):
def __init__(self,parent):
tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()

def initialize(self):
self.grid()
## Title ---------------------------------------
titlelbl = tkinter.Label(self, text="Calculadora da Taxa"
"de Juro Composto"
,
anchor="center",fg="white",
bg="blue")
titlelbl.grid(column=0,row=0,columnspan=3,sticky='EW')
## End Title & subtitle labels ---------------------------------------

## Input Labels --------------------------------------------------
principallbl = tkinter.Label(self, text="Investimento"
"Inicial:"
,
anchor="w",fg="white",
bg="SlateGray4")
principallbl.grid(column=0,row=1,columnspan=1,
sticky='EW')

intratelbl = tkinter.Label(self, text="Taxa de Juro"
"(% Anual):"
,
anchor="w",fg="white",bg="SlateGray4")
intratelbl.grid(column=0,row=2,columnspan=1,sticky='EW')

timescomplbl = tkinter.Label(self, text=" Número de Vezes"
"de Capitalização por Ano :"
,
anchor="w",fg="white",bg="SlateGray4")
timescomplbl.grid(column=0,row=3,columnspan=1,sticky='EW')

yrslbl = tkinter.Label(self, text="Números de Anos do"
"Investimento:"
,
anchor="w",fg="white",bg="SlateGray4")
yrslbl.grid(column=0,row=4,columnspan=1,sticky='EW')

amountlbl = tkinter.Label(self, text="Montante "
"Total:"
,
anchor="w",fg="white",bg="SlateGray4")
amountlbl.grid(column=0,row=6,columnspan=1,sticky='EW')

earnlbl = tkinter.Label(self, text="Juros Total:",
anchor="w",fg="white",bg="SlateGray4")
earnlbl.grid(column=0,row=7,columnspan=1,sticky='EW')
## end of input labels ------------------------------------------------
## Input Boxes --------------------------------------------------------

self.pr = tkinter.DoubleVar()
principal = tkinter.Entry(self,textvariable=self.pr)
principal.grid(column=1,row=1, sticky='EW')

self.rate = tkinter.DoubleVar()
intrate = tkinter.Entry(self,textvariable=self.rate)
intrate.grid(column=1,row=2, sticky='EW')

self.ntimes = tkinter.IntVar()
times = tkinter.Entry(self,textvariable=self.ntimes)
times.grid(column=1,row=3, sticky='EW')

self.years = tkinter.DoubleVar()
yrs = tkinter.Entry(self,textvariable=self.years)
yrs.grid(column=1,row=4, sticky='EW')
## end of input boxes -------------------------------------------------
## Button
button = tkinter.Button(self,text="Calcular",
command=self.OnButtonClick)
button.grid(column=0,row=5,columnspan=3)
## end of button

## Output labels
self.amt = tkinter.StringVar()
amtout = tkinter.Label(self,textvariable=self.amt,
anchor="e",fg="red",bg="yellow")
amtout.grid(column=1,row=6,columnspan=2,sticky='EW')

self.earn = tkinter.StringVar()
earnout = tkinter.Label(self,textvariable=self.earn,
anchor="e",fg="red",bg="gold")
earnout.grid(column=1,row=7,columnspan=2,sticky='EW')
## end of output labels -----------------------------------------------

self.grid_columnconfigure(0,weight=1)
self.resizable(True,False)

def OnButtonClick(self):
p = self.pr.get()
i = self.rate.get()
t = self.ntimes.get()
y = self.years.get()

## Compound Interest Calculation
amount = round((p * ((1 + ((i/100) / t))**(t * y))),2)
intearn = round((amount - p),2)
self.amt.set(amount)
self.earn.set(intearn)

if __name__ == "__main__":
app = compintapp_tk(None)
app.title('Calculadora da Taxa de Juro Composto')
app.mainloop()


Fonte: Osama Sidat (código aberto)



Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação