我正在用 Python 创建一个库存系统。Treeview 表总计列需要使用 python 计算和显示总和。我需要计算总计列的最终总数。我试过了,但我可以得到我到目前为止所尝试的结果,我附在下面。我有一个错误
sum1 += tot TypeError: +=: 'float' 和 'tuple' 不支持的操作数类型
我需要在上面的屏幕截图中计算像 400 + 5000 + 900 这样的列 tot 值;我表明我必须打印最终总数
from tkinter import *
from tkinter import ttk
import mysql.connector
def show():
tot = 0
if(var1.get()):
price = int(e1.get())
qty = int(e6.get())
tot = int(price * qty)
tempList = [['Thai Fried Rice', e1.get(), e6.get(), tot]]
tempList.sort(key=lambda e: e[1], reverse=True)
for i, (item, price, qty, tot) in enumerate(tempList,start=1):
listBox.insert("", "end", values=(item, price, qty, tot))
if (var2.get()):
price = int(e2.get())
qty = int(e7.get())
tot = int(price * qty)
tempList = [['Basil Fried Rice', e2.get(), e7.get(), tot]]
tempList.sort(key=lambda e: e[1], reverse=True)
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
listBox.insert("", "end", values=(item, price, qty, tot))
if (var3.get()):
price = int(e3.get())
qty = int(e8.get())
tot = int(price * qty)
tempList = [['Pineapple Fried Rice', e3.get(), e8.get(), tot]]
tempList.sort(key=lambda e: e[1], reverse=True)
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
listBox.insert("", "end", values=(item, price, qty, tot))
if (var4.get()):
price = int(e4.get())
qty = int(e9.get())
tot = int(price * qty)
tempList = [['Crab Fried Rice', e4.get(), e9.get(), tot]]
tempList.sort(key=lambda e: e[1], reverse=True)
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
listBox.insert("", "end", values=(item, price, qty, tot))
手掌心
相关分类