I am creating an inventory system in Python. Treeview table total column need to calculate and display sum using python. I need to calculate final total of total column. I tried but I could the result what I tried so far I attached below. I got an error
sum1 += tot TypeError: unsupported operand type(s) for +=: ‘float’ and ‘tuple’
I need to calculate column tot values like 400 + 5000 + 900 in above screenshot; I shown I have to print the final total
JavaScript
x
76
76
1
from tkinter import *
2
from tkinter import ttk
3
import mysql.connector
4
5
6
def show():
7
8
tot = 0
9
10
if(var1.get()):
11
12
price = int(e1.get())
13
qty = int(e6.get())
14
tot = int(price * qty)
15
16
tempList = [['Thai Fried Rice', e1.get(), e6.get(), tot]]
17
tempList.sort(key=lambda e: e[1], reverse=True)
18
19
for i, (item, price, qty, tot) in enumerate(tempList,start=1):
20
listBox.insert("", "end", values=(item, price, qty, tot))
21
22
if (var2.get()):
23
24
price = int(e2.get())
25
qty = int(e7.get())
26
tot = int(price * qty)
27
28
tempList = [['Basil Fried Rice', e2.get(), e7.get(), tot]]
29
tempList.sort(key=lambda e: e[1], reverse=True)
30
31
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
32
listBox.insert("", "end", values=(item, price, qty, tot))
33
34
if (var3.get()):
35
36
price = int(e3.get())
37
qty = int(e8.get())
38
tot = int(price * qty)
39
40
tempList = [['Pineapple Fried Rice', e3.get(), e8.get(), tot]]
41
tempList.sort(key=lambda e: e[1], reverse=True)
42
43
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
44
listBox.insert("", "end", values=(item, price, qty, tot))
45
46
if (var4.get()):
47
48
price = int(e4.get())
49
qty = int(e9.get())
50
tot = int(price * qty)
51
52
tempList = [['Crab Fried Rice', e4.get(), e9.get(), tot]]
53
tempList.sort(key=lambda e: e[1], reverse=True)
54
55
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
56
listBox.insert("", "end", values=(item, price, qty, tot))
57
58
if (var5.get()):
59
60
price = int(e5.get())
61
qty = int(e10.get())
62
tot = int(price * qty)
63
64
tempList = [['Fish Fried Rice', e5.get(), e10.get(), tot]]
65
tempList.sort(key=lambda e: e[1], reverse=True)
66
67
for i, (item, price, qty, tot) in enumerate(tempList, start=1):
68
listBox.insert("", "end", values=(item, price, qty, tot))
69
70
sum1 = 0.0
71
72
for tot in enumerate(tempList):
73
sum1 += tot
74
75
print(sum1)
76
Advertisement
Answer
Does something like this work? Change the last for
loop in show()
to this:
JavaScript
1
4
1
for child in listBox.get_children():
2
sum1 += float(listBox.item(child,'values')[3])
3
print(sum1)
4
Hope it solved your doubts, if any errors do let me know
Cheers