|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 豌图酱 于 2017-4-10 21:36 编辑
- from tkinter import *
- class Calculator:
- def __init__(self):
- window = Tk()
-
-
- Label(window,text='Investment Amount').grid(row=0,column=0,sticky=W)
- Label(window,text='Years').grid(row=1,column=0,sticky=W)
- Label(window,text='Annual Interest Rate').grid(row=2,column=0,sticky=W)
- Label(window,text='Future Value').grid(row=3,column=0,sticky=W)
- self.investmentAmount = StringVar()
- Entry(window,textvariable=self.investmentAmount,justify=RIGHT).grid(row=0,column=1)
- self.years = StringVar()
- Entry(window,textvariable=self.years,justify=RIGHT).grid(row=1,column=1)
- self.annualInterestRate = StringVar()
- Entry(window,textvariable=self.annualInterestRate,justify=RIGHT).grid(row=2,column=1)
- self.futureValueVar = StringVar
- Label(window,textvariable=self.futureValueVar).grid(row=3,column=1,sticky=E)
- bt = Button(window,text='Calculate',command=self.calculate)
- bt.grid(row=4,column=1,sticky=E)
- mainloop()
- def calculate(self):
-
- result = float(self.investmentAmount.get())*(1+float(self.annualInterestRate.get())/1200)**(int(self.years.get())*12)
- self.futureValueVar.set(result)
- Calculator()
复制代码
是要创建一个投资值计算器,然而运行后报错,想请大家帮我看下问题出在哪里
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1550, in __call__
return self.func(*args)
File "C:/Users/lenovo/Desktop/python/python语言程序设计书本资料/9.2投资计算器.py", line 26, in calculate
self.futureValueVar.set(result)
TypeError: set() missing 1 required positional argument: 'value'
运行界面如下
第18行 self.futureValueVar = StringVar少了括号,变成了StringVar函数,所以报错少了参数
|
|