Question
Start by getting the Listing 10.11 LoanCalculator.py program running: from tkinter import * # Import tkinter class LoanCalculator: def __init__(self): window = Tk() # Create
Start by getting the Listing 10.11 LoanCalculator.py program running: from tkinter import * # Import tkinter class LoanCalculator: def __init__(self): window = Tk() # Create a window window.title("Loan Calculator") # Set title Label(window, text = "Annual Interest Rate").grid(row = 1, column = 1, sticky = W) Label(window, text = "Number of Years").grid(row = 2, column = 1, sticky = W) Label(window, text = "Loan Amount").grid(row = 3, column = 1, sticky = W) Label(window, text = "Monthly Payment").grid(row = 4, column = 1, sticky = W) Label(window, text = "Total Payment").grid(row = 5, column = 1, sticky = W) self.annualInterestRateVar = FILL_CODE_OR_CLICK_ANSWER Entry(window, textvariable = self.annualInterestRateVar, justify = RIGHT).grid(row = 1, column = 2) self.numberOfYearsVar = StringVar() Entry(window, FILL_CODE_OR_CLICK_ANSWER, justify = RIGHT).grid(row = 2, column = 2) self.loanAmountVar = StringVar() Entry(window, textvariable = self.loanAmountVar, justify = RIGHT).grid(row = 3, column = 2) self.monthlyPaymentVar = StringVar() lblMonthlyPayment = Label(window, textvariable = self.monthlyPaymentVar).grid(row = 4, column = 2, sticky = E) self.totalPaymentVar = StringVar() lblTotalPayment = Label(window, textvariable = self.totalPaymentVar).grid(row = 5, column = 2, sticky = E) btComputePayment = Button(window, text = "Compute Payment", command = FILL_CODE_OR_CLICK_ANSWER).grid( row = 6, column = 2, sticky = E) window.mainloop() # Create an event loop def computePayment(self): monthlyPayment = self.getMonthlyPayment( float(self.loanAmountVar.get()), float(self.annualInterestRateVar.get()) / 1200, int(FILL_CODE_OR_CLICK_ANSWER)) self.monthlyPaymentVar.set(format(monthlyPayment, '10.2f')) totalPayment = float(self.monthlyPaymentVar.get()) * 12 \ * int(self.numberOfYearsVar.get()) self.totalPaymentVar.set(format(totalPayment, '10.2f')) def getMonthlyPayment(self, loanAmount, monthlyInterestRate, numberOfYears): monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / (1 + monthlyInterestRate) ** (numberOfYears * 12)) return monthlyPayment; LoanCalculator() # Create GUI
The execution window looks as follows:
Modify the program to provide another input for a revised monthly payment, and output for a revised loan amount. The Compute Loan Amount button will compute a new Loan amount using the adjusted monthly payment, but using the same interest rate and number of years:
To get full credit, add spacing around the outside of the form and between the Compute Payment button and the Monthly Payment Entry box. You accomplish this by adding grid rows and columns containing spaces.
The following two methods should help:
def computeLoan(self): loanAmount2 = self.getLoanAmount(float(self.monthlyPaymentVar2.get()), float(self.annualInterestRateVar.get()) / 1200, int(self.numberOfYearsVar.get())) self.loanAmountVar2.set(format(loanAmount2, '10.2f')) def getLoanAmount(self, monthlyPayment, monthlyInterestRate, numberOfYears): loanAmount = monthlyPayment * (1 - 1 / (1 + monthlyInterestRate) ** (numberOfYears * 12)) / monthlyInterestRate return loanAmount;
Add your name as a comment in the program and attach it below.
Python Please
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started