我对此代码有问题。要计算你每月要付多少房贷,尽管我和每个人都谈过,但都不能确定问题出在哪里。所以我来这里是想看看你们谁能帮忙?非常感谢:)
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()
您应该调用
set
方法,而不是赋值给它。。。去掉等号。你知道吗在代码开头添加:
另外,如果您使用的是Python2,那么可以这样编写Tk导入:
相关问题 更多 >
编程相关推荐