from tkinter import *
class taxaesforco:
def __init__(self):
window = Tk()
window.title("Taxa de Esforço")
Label(window, text = "Rendimento Mensal Líquido: €")
.grid(row = 1,column = 1, sticky = W)
Label(window, text = "Crédito à habitação: €")
.grid(row = 2,column = 1, sticky = W)
Label(window, text = "Crédito Automóvel: €")
.grid(row = 3,column = 1, sticky = W)
Label(window, text = "Crédito Pessoal: €")
.grid(row = 4,column = 1, sticky = W)
Label(window, text = "Dívida do Cartão de Crédito: € ")
.grid(row = 5,column = 1, sticky = W)
Label(window, text = "Outros Créditos: € ")
.grid(row = 6,column = 1, sticky = W)
Label(window, text = "Taxa de Esforço (em %)")
.grid(row = 7,column = 1, sticky = W)
self.rendimentoVar = StringVar()
Entry(window, textvariable = self.rendimentoVar,
justify = RIGHT).grid(row = 1, column = 2)
self.chabitacaoVar = StringVar()
Entry(window, textvariable = self.chabitacaoVar,
justify = RIGHT).grid(row = 2, column = 2)
self.cautomovelVar = StringVar()
Entry(window, textvariable = self.cautomovelVar,
justify = RIGHT).grid(row = 3, column = 2)
self.cpessoalVar = StringVar()
Entry(window, textvariable = self.cpessoalVar,
justify = RIGHT).grid(row = 4, column = 2)
self.ccreditoVar = StringVar()
Entry(window, textvariable = self.ccreditoVar,
justify = RIGHT).grid(row = 5, column = 2)
self.outrocroditoVar = StringVar()
Entry(window, textvariable = self.outrocroditoVar,
justify = RIGHT).grid(row = 6, column = 2)
self.taxaesforcoVar = StringVar()
lblesforco = Label(window, textvariable =
self.taxaesforcoVar).grid(row = 7, column = 2,
sticky = E)
lbtComputePayment = Button(window,text ="Compute Payment",
command=self.computePayment).grid(
row = 8, column = 2, sticky = E)
window.mainloop()
def computePayment(self):
esforco = self.gettaxaesforco(
float(self.rendimentoVar.get()),
float(self.chabitacaoVar.get()),
float(self.cautomovelVar.get()),
float(self.cpessoalVar.get()),
float(self.ccreditoVar.get()),
float(self.outrocroditoVar.get()))
self.taxaesforcoVar.set(format(esforco, '0.2f'))
def gettaxaesforco(self,
rendimento, chabitacao, cautomovel,cpessoal,ccredito,
outrocrodito):
credito=(chabitacao+cautomovel+cpessoal+ccredito
+outrocrodito)
esforco =(credito*100)/(rendimento)
return esforco;
taxaesforco()