Question
how do I write a GUI-based program that displays labeled fields for the inputs and a text area for the output? here is what I
how do I write a GUI-based program that displays labeled fields for the inputs and a text area for the output? here is what I have so far, i can't get the numbers to line up.
from breezypythongui import EasyFrame
class TidbitGUI(EasyFrame):
def __init__(self):
"""Set up the window and widgets."""
EasyFrame.__init__(self, title = "Tidbit Loan Scheduler")
"""Input fields"""
self.addLabel(text = "Purchase Price: ", row = 0, column = 0)
self.addLabel(text = "Annual Intrest Rate in %: ", row = 1, column = 0 )
self.purchasePrice = self.addFloatField(value = 0.0, row = 0, column = 1)
self.rate = self.addFloatField(value = 0, row = 1, column = 1)
"""Command button"""
self.outputArea = self.addTextArea("", row = 4, column = 0, columnspan = 2, width = 80, height = 20)
"""Output text box"""
self.calculate = self.addButton(text = "Compute", row = 3, column =0, columnspan = 2, command = self.calculateor)
def calculateor(self):
purchase_Price = self.purchasePrice.getNumber()
rate = (self.rate.getNumber()/100)
if purchase_Price ==0 or rate == 0:
return
ANNUAL_RATE = .12
MONTHLY_RATE = ANNUAL_RATE / 12
downPayment = purchase_Price * 0.1
purchasePrice = purchase_Price - downPayment
monthlyPayment = rate * purchase_Price
month = 1
balance = purchase_Price
string=("Month Starting Balance Interest to Pay Principal to Pay Payment Ending Balance")
while balance > 0:
if monthlyPayment > balance:
monthlyPayment = balance
interest = 0
else:
interest = balance * MONTHLY_RATE
principal = monthlyPayment - interest
remaining = balance - principal
string += ("%2d%15.2f%15.2f%17.2f%17.2f%17.2f" % (month, balance, interest, principal, monthlyPayment, remaining))
balance = remaining
month += 1
self.outputArea["state"] = "normal"
self.outputArea.setText(string)
self.outputArea["state"] = "disabled"
def main():
"""Instantiate and pop up the window."""
TidbitGUI().mainloop()
if __name__ == "__main__":
try:
while True:
main()
except KeyboardInterrupt:
print(" Program closed.")
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