2

I have a database returning the total of several column and I am trying to display it in a treeview. If I do

for i in backend2.calc_total()[0]:
    treeviewtotal.insert("", END, values=i)

I get

which is not what i want as i want everything to start from "food" column onwards. I cant make date a iid as i already have an iid that I am referencing to my database.

If I do

list2 = ['Date', 'Food', 'Transport', 'Insurance', 'Installments', 'Others']
for i in range(len(backend2.calc_total()[0][0])):
     treeviewtotal.insert("", 0, list2[i+1], values=backend2.calc_total()[0][0][i])

I get this

instead, all the totals get stacked into 1 column (which is scrollable).

Any way to achieve my aim of allocating the respective totals to the respective column in a same row? Thanks!

furas
  • 134,197
  • 12
  • 106
  • 148
  • maybe you shoud use column number `i` instead of 0 (zero) in `insert(..., i+1, ...)`. Or use `END` and first insert empty string which will be insterd as `Date` – furas Jul 06 '19 at 19:01

1 Answers1

0

With reference to the first attempt, the following solves the problem:

for i in backend2.calc_total()[0]:
        treeviewtotal.insert("", END, values=([], *i))

values= takes in a list. Therefore we add an empty space by using [], but since i itself is already a list, we need to "flatten out" the list by doing *i.

Please correct me if I used any parts of the code wrongly. Still trying to learn =)