我一直在尝试使用文本中的输入对其进行一些计算,将其保存为另一个变量然后打印。这是代码:
import PySimpleGUI as sg
def fixedDepositCalc1():
layout = [
[sg.Text("What is your principle amount?:")],
[sg.I(key='-PRINCIPLE-')],
[sg.Text("What is your interest rate for your deposit? Please give your answer in a percent form:")],
[sg.I(key='-RATE-')],
[sg.Text("What is the tenure for your fixed deposit?:")],
[sg.I(key='-TIME-')],
[sg.B("Ok")]
]
window4 = sg.Window("Fixed Deposit Calculator - Financial Manager").Layout(layout)
event, values = window4.read()
if event == "Ok":
I_MONEY = float(values('-PRINCIPLE-')) * float((values('-RATE-')/100)) * float(values('TIME'))
P_MONEY = float(values('-PRINCPLE-')) + I_MONEY
global principle
principle = float(values='-PRINCIPLE-')
layout2 = [
[sg.T(f"Your principle amount is{principle}")]
]
window5 = sg.Window("Fixed Deposit Calculator - Financial Manager").Layout(layout2)
event, values = window5.read()
这里是弹出的错误
File "c:\Users\Kashyap\Desktop\pysimplegui\fixedDepositCalc.py", line 19, in fixedDepositCalc1
I_MONEY = float(values('-PRINCIPLE-')) * float((values('-RATE-')/100)) * float(values('TIME'))
TypeError: 'dict' object is not callable
我试图将 values 变量保存为另一个变量,以便我可以使用它。
values
是dict类型,所以你应该用[xxx]
取值,然后你的代码有一些小问题,我给你改正了,你可以试试
import PySimpleGUI as sg
def fixedDepositCalc1():
layout = [
[sg.Text("What is your principle amount?:")],
[sg.I(key="-PRINCIPLE-")],
[
sg.Text(
"What is your interest rate for your deposit? Please give your answer in a percent form:"
)
],
[sg.I(key="-RATE-")],
[sg.Text("What is the tenure for your fixed deposit?:")],
[sg.I(key="-TIME-")],
[sg.B("Ok")],
]
window4 = sg.Window("Fixed Deposit Calculator - Financial Manager").Layout(layout)
event, values = window4.read()
if event == "Ok":
I_MONEY = (
float(values["-PRINCIPLE-"])
* (float(values["-RATE-"]) / 100)
* float(values["-TIME-"])
)
P_MONEY = float(values["-PRINCIPLE-"]) + I_MONEY
global principle
principle = float(values["-PRINCIPLE-"])
layout2 = [[sg.T(f"Your principle amount is{principle}")]]
window5 = sg.Window("Fixed Deposit Calculator - Financial Manager").Layout(layout2)
event, values = window5.read()