Python Forum

Full Version: Update label if there are no records in treeview
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello good,

I am trying to add and subtract values from a treeview column.

So far so good, I show a label and it updates if I add another value to the column.

When you remove a value from the column, it is subtracted. Well, it does, but it shows me the minus symbol "-" (-10$) in front of it. Example. And now when I finish eliminating all the values in the column and the treeview runs out of data, the result of the label shows me the last subtraction done.

def calcular_total(self):
        self.suma_total = 0
        for item in self.treeview_cesta.get_children():
            self.valor = int(self.treeview_cesta.item(item, "values")[3])  # Cambia el índice (1) al número de columna que desees sumar
            self.suma_total += self.valor
            self.entry_total_cesta.config(text=self.suma_total)
[Image: eYzxDH8.png]

[Image: WVn9GFk.png]

What could I do so that when there is nothing in the treeview it shows 0$? and remove the symbol (minus "-")
could use if statement example
if sum_total < 0:
    sum_total = 0