我遇到此代码的问题。要计算抵押贷款你每月支付的抵押贷款金额,尽管我所说的每个人都无法确定问题所在。所以我来到这里看看你们中是否有人能够提供帮助?非常感谢:)
from tkinter import * #Imports the tkinter library
mortgage=Tk() #Names the interface as 'mortgage'
mortgage.geometry("800x500+200+200") #Defines the dimensions of the interface
mortgage.title("Mortgage")
#calculation method
def Calculate():
loantotal1=float(loantotal.get())
interestrate1=float(interestrate.get())
loanperiod1=float(loanperiod.get())
interestCalculation =float( interestrate1 / 100)
totalcost = float(loantotal1 * interestCalculation)
numberofmonths=float(loanperiod1 / 12)
monthlycost= float(totalcost / loanperiod1)
monthly_period.set=("Your monthly payment %2.f "%monthlycost)
#variables
loantotal=StringVar()
interestrate=StringVar()
loanperiod=StringVar()
monthly_period=StringVar()
#interface
welcome_message=Label(mortgage,text="Find out how much you'll pay monthly for your mortgage,",font="Arial 12 bold",fg="#000000").pack()
instruction_message=Label(mortgage,text="Enter your details below and then Click submit:",font="Arial 12 bold",fg="#000000").pack()
loanTotal=Label(mortgage,text="Loan Total:",font="Arial 11 bold",fg="#000000").place(x=280,y=63)
loanTotal=Label(mortgage,text="£",font="Arial 11 bold",fg="#000000").place(x=550,y=63)
loanTotal_textbox=Entry(mortgage,textvariable=loantotal).place(x=400,y=65)
interestRate=Label(mortgage,text="Interest Rate:",font="Arial 11 bold",fg="#000000").place(x=280,y=88)
interestRate=Label(mortgage,text="%",font="Arial 11 bold",fg="#000000").place(x=550,y=88)
interestRate_textbox=Entry(mortgage,textvariable=interestrate).place(x=400,y=90)
loanPeriod=Label(mortgage,text="Loan Period:",font="Arial 11 bold",fg="#000000").place(x=280,y=113)
loanPeriod=Label(mortgage,text="Years",font="Arial 11 bold",fg="#000000").place(x=550,y=113)
loanPeriod_textbox=Entry(mortgage,textvariable=loanperiod).place(x=400,y=115)
Label(mortgage,textvariable=monthly_period).place(x=400,y=135)
submit_button=Button(mortgage,text="Calculate",command=Calculate,font="Arial 11 bold",fg="#000000").place(x=280,y=170)
mortgage.mainloop()
答案 0 :(得分:1)
monthly_period.set=("Your monthly payment %2.f "%monthlycost)
您应该调用set
方法,而不是分配给它...删除等号。
答案 1 :(得分:0)
在代码的开头添加:
# -*- coding: utf-8 -*-
此外,如果您使用的是Python2,请按以下方式编写Tk导入:
from Tkinter import * #Imports the tkinter library