【发布时间】:2021-06-22 08:17:31
【问题描述】:
问题出现在这行代码 newAmountForAcc1 = int(currBalance) - int(amountToBeSent),我只想将金额从一个银行账户转移到另一个银行账户,我有一个输入框(我使用Tkinter),以获取我使用 .get() 函数的数量。当我运行代码时,它显示 ValueError: invalid literal for int() with base 10: ''。这是函数
def transferMoney():
newTransactionWindow = Tk()
newTransactionWindow.title("Money Transfer")
global secAcc
secAcc=Entry(newTransactionWindow)
secAcc.grid(row=0, column=1, padx=30)
global amount
amount=Entry(newTransactionWindow)
amount.grid(row=1, column=1, padx=30)
secAccLabel = Label(newTransactionWindow, text="Enter Receiver's Account number:")
secAccLabel.grid(row=0, column=0, padx=30)
amountLabel = Label(newTransactionWindow, text="Enter the amount to send:")
amountLabel.grid(row=1, column=0, padx=30)
amountToBeSent = amount.get()
acc1 = deleteBox.get()
acc2 = secAcc.get()
statement1=f"select * from bank where ACC_NUM={acc1}"
mycursor.execute(statement1)
record = mycursor.fetchall()
currBalance = 0
for x in record:
currBalance = x[7]
newAmountForAcc1 = int(currBalance) - int(amountToBeSent)
statement2=f"update bank set BALANCE = {newAmountForAcc1} where ACC_NUM={acc1}"
mycursor.execute(statement2)
newAmountForAcc2 = currBalance + amountToBeSent
statement4 = f"update bank set BALANCE = {newAmountForAcc2} where ACC_NUM={acc2}"
mycursor.execute(statement4)
sendMoneyButton = Button(newTransactionWindow, text="Send Money", command=send)
sendMoneyButton.grid(row=2, column=0, columnspan=2, pady=10, ipadx=50)
mydb.commit()
transactionCompletedWindow = Tk()
transactionCompletedWindow.title("Transaction successful")
transactionCompletedWindowLabel = Label(transactionCompletedWindow, text="Transaction completed successfully")
【问题讨论】:
-
您的值之一是空字符串,不能转换为 int。追溯该值的来源!
标签: python transactions valueerror tkinter-entry