Desenvolvendo uma Mini Calculadora Financeira no Python
Calculadora de Juros Simples
""" CALCULADORA DE JUROS SIMPLES"""
def calc_juros_simples1(VF, periodos, taxa_anual):
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
VP = round((VF / (1 + periodos_meses*taxa_mensal)),2)
return VP
def calc_juros_simples2(VP, periodos, taxa_anual):
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
VF = round(VP * (1 + periodos_meses*taxa_mensal),2)
return VF
def calc_juros_simples3(VF, VP, periodos):
periodos_meses = periodos * 12
taxa_mensal = round(((VF / VP) -1)/(periodos_meses),2)
return taxa_mensal*100
def calc_juros_simples4(VF, VP, taxa_anual):
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = round(((VF/VP)-1)/(taxa_mensal),2)
return periodos_meses
Calculadora de Juros Compostos Pagamento Simples
def calc_juros_compostos1(VF, periodos, taxa_anual):
""" CALCULADORA DE JUROS COMPOSTOS PAGAMENTOS SIMPLES"""
periodos_meses = periodos * 12
taxa_mensal = (taxa_anual / 12)/100
VP = round(VF / ((1 + taxa_mensal)**periodos_meses),2)
juros = round((VF-VP),2)
return VP
def calc_juros_compostos2(VP, periodos, taxa_anual):
periodos_meses = periodos * 12
taxa_mensal = (taxa_anual / 12)/100
VF = round(VP * ((1 + taxa_mensal)**periodos_meses),2)
juros = round((VF-VP),2)
return VF
def calc_juros_compostos3(VF, VP, periodos):
periodos_meses = periodos * 12
taxa_mensal = round(((VF / VP)**(1/periodos_meses))-1,2)
return taxa_mensal*100
def calc_juros_compostos4(VF, VP, taxa_anual):
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = round((math.log(VF/VP))/(math.log(1+taxa_mensal)),2)
return periodos_meses
Calculadora de Juros Compostos Séries Uniformes Postecipadas
""" CALCULADORA DE JUROS COMPOSTOS SÉRIES UNIFORMES POSTECIPADAS"""
def calc_serie_uniforme11(PGTO, periodos, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
#mostra o resultado
VP = PGTO*((((1+taxa_mensal)**periodos_meses)-1)/(taxa_mensal*(((1+taxa_mensal)**periodos_meses))))
return VP
# ------------------------------------------------------------------------------------
def calc_serie_uniforme21(PGTO, periodos, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
#mostra o resultado
VF = PGTO*((((1+taxa_mensal)**periodos_meses)-1)/taxa_mensal)
return VF
#--------------------------------------------------------------------------------------
def calc_serie_uniforme31(VF, periodos, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
PGTO = 0
#mostra o resultado
PGTO = round(((VF*taxa_mensal)/((1+taxa_mensal)**periodos_meses-1)),2)
return PGTO
#--------------------------------------------------------------------------------------------
def calc_serie_uniforme41(VF, PGTO, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
#mostra o resultado
periodos_meses = ((math.log((VF*taxa_mensal/PGTO)+1))/(math.log(1+taxa_mensal)))
return periodos_meses
#------------------------------------------------------------------------------------------------
def calc_serie_uniforme51(VF, VP, PGTO, periodos):
#converte valores anuais para valores mensais
periodos_meses = periodos * 12
#mostra o resultado
dif = 1
dif2 = 1
taxa_mensal = 0.0000000005
if VP == 1.0:
while dif > 0:
taxa_mensal +=0.000005
dif = (VF/PGTO)-((((1+taxa_mensal)**periodos_meses)-1)/taxa_mensal)
else:
while dif2 > 0:
taxa_mensal +=0.005
dif2 = (VP/PGTO)-((((1+taxa_mensal)**periodos_meses)-1)/(taxa_mensal*((1+taxa_mensal)**periodos_meses)))
return taxa_mensal*100
Calculadora de Juros Compostos Séries Uniformes Antecipadas
""" CALCULADORA DE JUROS COMPOSTOS SÉRIES UNIFORMES ANTECIPADAS"""
def calc_serie_uniforme12(PGTO, periodos, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
VP = PGTO*((((1+taxa_mensal)**periodos_meses)-1))/(taxa_mensal*((1+taxa_mensal)**(periodos_meses-1)))
return VP
# ------------------------------------------------------------------------------------
def calc_serie_uniforme22(PGTO, periodos, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos * 12
VF = (PGTO*((((1+taxa_mensal)**periodos_meses)-1)/taxa_mensal))*(1+taxa_mensal)
return VF
#--------------------------------------------------------------------------------------
def calc_serie_uniforme32(VF, periodos, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
periodos_meses = periodos*12
#mostra o resultado
PGTO = (VF*taxa_mensal)/((((1+taxa_mensal)**periodos_meses)-1)*(1+taxa_mensal))
return PGTO
#--------------------------------------------------------------------------------------------
def calc_serie_uniforme42(VF, VP, taxa_anual):
#converte valores anuais para valores mensais
taxa_mensal = (taxa_anual / 12) / 100
#mostra o resultado
periodos_meses = (math.log((VF*taxa_mensal/(PGTO*(1+taxa_mensal)))+1))/(math.log(1+taxa_mensal))
return periodos_meses
#------------------------------------------------------------------------------------------------
def calc_serie_uniforme52(VF, VP, PGTO, periodos):
#converte valores anuais para valores mensais
periodos_meses = periodos * 12
#mostra o resultado
dif = 1
dif2 = 1
taxa_mensal = 0.0000000005
if VP == 1.0:
while dif > 0:
taxa_mensal +=0.000005
dif = (VF/PGTO)-(((((1+taxa_mensal)**periodos_meses)-1)/taxa_mensal))*(1+taxa_mensal)
else:
while dif2 > 0:
taxa_mensal +=0.005
dif2 = (VP/PGTO)-((((1+taxa_mensal)**periodos_meses)-1)/(taxa_mensal*((1+taxa_mensal)**(periodos_meses-1))))
print(dif2)
return taxa_mensal*100
Ela no TKinter
import math
import pandas as pd
import tkinter as tk
from tkinter import ttk
from tkinter import *
from PIL import ImageTk, Image
import os
# tkinter GUI
root= tk.Tk()
root.title('Calculadora Financeira')
#root.rowconfigure(0,weight=1)
#root.columnconfigure([0,1],weight=1)
canvas1 = tk.Canvas(root, width = 500, height = 350)
canvas1.pack()
tipo_calculo = tk.Label(root, text='Selecione o Tipo de Calculo', bg='#000066', fg='#FFFFFF', font=("Arial Black",8))
#panel1 = tk.Label(root, text=tipo_serie)
canvas1.create_window(110,50, window=tipo_calculo)
#Cria o dicionário com os nomes nas chaves e o tipo no valor
dicionario_tipo_calculo = {
'Juros Simples': 'S',
'Juros Compostos': 'C',
'Série Postecipada': 'P',
'Série Antecipada': 'A',
}
#Cria uma lista com as chaves do dicionário_tipo_serie
tipos = list(dicionario_tipo_calculo.keys())
#Cria uma Combobox para exibir as chaves na lista anterior
tipo = ttk.Combobox(root, values=tipos)
canvas1.create_window(270,50, window=tipo)
#img = ImageTk.PhotoImage(Image.open('Bertolo.jpg'))
#panel = tk.Label(root, image = img)
#canvas1.create_window(440,90, window=panel)
label0 = tk.Label(root, text=' IMES Catanduva - Prof. Bertolo', bg='#990000', fg='white', font=("Arial Black", 14))
canvas1.create_window(200,20, window=label0)
label7 = tk.Label(root, text=' Digite os valores e naquele desejado entre com ZERO e no opcional 1', bg='#990000', fg='yellow', font=("Arial Black", 8))
canvas1.create_window(250,190, window=label7)
# VP
label1 = tk.Label(root, text=' VP em R$ :')
canvas1.create_window(140, 80, window=label1)
entry1 = tk.Entry (root)
canvas1.create_window(270, 80, window=entry1)
Resultado = (' ')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
# VF
label2 = tk.Label(root, text=' VF em R$ :')
canvas1.create_window(140, 100, window=label2)
entry2 = tk.Entry (root)
canvas1.create_window(270, 100, window=entry2)
# PGTO
label3 = tk.Label(root, text=' PGTO em R$ :')
canvas1.create_window(140, 120, window=label3)
entry3 = tk.Entry (root)
canvas1.create_window(270, 120, window=entry3)
# periodos
label4 = tk.Label(root, text=' Períodos em anos :')
canvas1.create_window(140, 140, window=label4)
entry4 = tk.Entry (root)
canvas1.create_window(270, 140, window=entry4)
# taxa
label5 = tk.Label(root, text='Taxa de juros anual em % : ')
canvas1.create_window(140, 160, window=label5)
entry5 = tk.Entry (root)
canvas1.create_window(270, 160, window=entry5)
def values1():
global VP
VP = float(entry1.get())
global VF
VF = float(entry2.get())
global PGTO
PGTO = float(entry3.get())
global periodos
periodos = float(entry4.get())
global taxa_anual
taxa_anual = float(entry5.get())
if VP ==0:
calc_juros_simples1(VP,periodos,taxa_anual)
Resultado = (' O Valor Presente foi de R$', round(calc_juros_simples1(VF,periodos,taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif VF ==0:
calc_juros_simples2(VP, periodos, taxa_anual)
Resultado = (' O Valor Futuro foi de R$', round(calc_juros_simples2(VP, periodos, taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif taxa_anual ==0:
calc_juros_simples3(VF, VP, periodos)
Resultado = (' A taxa foi de', round(calc_juros_simples3(VF, VP, periodos),2),' % a.m.')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif periodos ==0:
calc_juros_simples4(VF, VP, taxa_anual)
Resultado = (' O número de períodos foi de', round(calc_juros_simples4(VF, VP, taxa_anual),2), 'meses')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
else:
Resultado = (' Houve ERRO na entrada de dados')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
def values2():
global VP
VP = float(entry1.get())
global VF
VF = float(entry2.get())
global PGTO
PGTO = float(entry3.get())
global periodos
periodos = float(entry4.get())
global taxa_anual
taxa_anual = float(entry5.get())
if VP ==0:
calc_juros_compostos1(VF, periodos, taxa_anual)
Resultado = (' O Valor Presente foi de R$', calc_juros_compostos1(VF,periodos,taxa_anual))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif VF ==0:
calc_juros_compostos2(VP, periodos, taxa_anual)
Resultado = (' O Valor Futuro foi de R$', calc_juros_compostos2(VP, periodos, taxa_anual))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif taxa_anual ==0:
calc_juros_compostos3(VF, VP, periodos)
Resultado = (' A taxa foi de', calc_juros_compostos3(VF, VP, periodos),' % a.m.')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif periodos ==0:
calc_juros_compostos4(VF, VP, taxa_anual)
Resultado = (' O número de períodos foi de', calc_juros_compostos4(VF, VP, taxa_anual), 'meses')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
else:
Resultado = (' Houve ERRO na entrada de dados')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
def values3():
global VP
VP = float(entry1.get())
global VF
VF = float(entry2.get())
global PGTO
PGTO = float(entry3.get())
global periodos
periodos = float(entry4.get())
global taxa_anual
taxa_anual = float(entry5.get())
if VP ==0:
calc_serie_uniforme11(PGTO, periodos, taxa_anual)
Resultado = (' O Valor Presente foi de R$ ',round(calc_serie_uniforme11(PGTO, periodos, taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif VF ==0:
calc_serie_uniforme21(PGTO, periodos, taxa_anual)
Resultado = (' O Valor Futuro foi de R$', round(calc_serie_uniforme21(PGTO, periodos, taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif PGTO ==0:
calc_serie_uniforme31(VF, periodos, taxa_anual)
Resultado = (' O PGTO foi de R$ ',round(calc_serie_uniforme31(VF, periodos, taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif taxa_anual ==0:
calc_serie_uniforme51(VF, VP, PGTO, periodos)
Resultado = (' A taxa foi de {:.3f}'.format(calc_serie_uniforme51(VF, VP, PGTO, periodos)),' % a.m.')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif periodos ==0:
calc_serie_uniforme41(VF,PGTO, taxa_anual)
Resultado = (' O número de períodos foi de', round(calc_serie_uniforme41(VF, PGTO, taxa_anual),2), 'meses')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
else:
Resultado = (' Houve ERRO na entrada de dados')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
def values4():
global VP
VP = float(entry1.get())
global VF
VF = float(entry2.get())
global PGTO
PGTO = float(entry3.get())
global periodos
periodos = float(entry4.get())
global taxa_anual
taxa_anual = float(entry5.get())
if VP ==0:
calc_serie_uniforme12(PGTO, periodos, taxa_anual)
Resultado = (' O Valor Presente foi de R$ ',round(calc_serie_uniforme12(PGTO, periodos, taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif VF ==0:
calc_serie_uniforme22(PGTO, periodos, taxa_anual)
Resultado = (' O Valor Futuro foi de R$ ', round(calc_serie_uniforme22(PGTO, periodos, taxa_anual),2))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif PGTO ==0:
calc_serie_uniforme32(VF, periodos, taxa_anual)
Resultado = (' O PGTO foi de R$ ', calc_serie_uniforme32(VF, periodos, taxa_anual))
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif taxa_anual ==0:
calc_serie_uniforme52(VF, VP, PGTO, periodos)
Resultado = (' A taxa foi de', round(calc_serie_uniforme52(VF, VP, PGTO, periodos),2),' % a.m.')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
elif periodos ==0:
calc_serie_uniforme42(VF, VP, taxa_anual)
Resultado = (' O número de períodos foi de', round(calc_serie_uniforme42(VF, PGTO, taxa_anual),2), 'meses')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
else:
Resultado = (' Houve ERRO na entrada de dados')
label_Resultado = tk.Label(root, text= Resultado, bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
def limpa_values():
entry1.delete(0,tk.END)
entry2.delete(0,tk.END)
entry3.delete(0,tk.END)
entry4.delete(0,tk.END)
entry5.delete(0,tk.END)
label_Resultado = tk.Label(root, text= ' ', bg='#000066', fg='#FFFFFF', font=("Arial Black", 10))
canvas1.create_window(200, 300, window=label_Resultado)
#Cria a função buscar_tipo_serie
def buscar_tipo_calculo():
tipo_preenchido = tipo.get() #pega a chave no dicionário que o nome do tipo
tipo_calculo = dicionario_tipo_calculo.get(tipo_preenchido) #Pega o VALOR da moeda_preenchida no dicionário
#mensagem_tipo = tk.Label(text="Tipo não encontrado")
#mensagem_tipo.grid(row=3, column=0)
#if tipo_serie:
#mensagem_tipo["text"] = f'O tipo da serie {tipo_preenchido} é de {serie_tipo} reais'
if tipo_calculo =='S':
values=values1()
elif tipo_calculo =='C':
values=values2()
elif tipo_calculo =='P':
values=values3()
else:
values=values4()
return values
button1 = tk.Button (root, text=' Calcular ', command=buscar_tipo_calculo, relief="raised", bd=10, bg='#000066', fg='white', font=("Arial Black", 12))
canvas1.create_window(280, 240, window=button1)
button2 = tk.Button (root, text=' Limpar ', command=limpa_values, relief="raised", bd=10, bg='#000066', fg='white', font=("Arial Black", 12))
canvas1.create_window(110, 240, window=button2)
root.mainloop()