我正在用 Python 创建一个库存系统。Treeview 表总计列需要使用 python 计算和显示总和。我需要计算总计列的最终总数。我试过了,但我可以得到我到目前为止所尝试的结果,我附在下面。我有一个错误sum1 += tot TypeError: +=: 'float' 和 'tuple' 不支持的操作数类型我需要在上面的屏幕截图中计算像 400 + 5000 + 900 这样的列 tot 值;我表明我必须打印最终总数from tkinter import *from tkinter import ttkimport mysql.connectordef 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))
1 回答

手掌心
TA贡献1942条经验 获得超3个赞
这样的东西有用吗?将最后一个for循环更改show()为:
for child in listBox.get_children():
sum1 += float(listBox.item(child,'values')[3])
print(sum1)
希望它解决了你的疑惑,如果有任何错误请告诉我
添加回答
举报
0/150
提交
取消