Python Forum
[Tkinter] Update label if there are no records in treeview
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Update label if there are no records in treeview
#1
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 "-")
Reply
#2
could use if statement example
if sum_total < 0:
    sum_total = 0
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter - update/refresh treeview snakes 5 21,227 Dec-02-2023, 07:05 PM
Last Post: aynous19
  Doubt approach update 2 Treeview at the same time TomasSanchexx 7 2,066 Sep-19-2023, 01:19 AM
Last Post: SaintOtis12
  [Tkinter] Can't update label in new tk window, object has no attribute tompranks 3 3,646 Aug-30-2022, 08:44 AM
Last Post: tompranks
  [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? CyKlop 5 3,448 Oct-20-2021, 12:14 AM
Last Post: CyKlop
  update text variable on label with keypress knoxvilles_joker 3 5,005 Apr-17-2021, 11:21 PM
Last Post: knoxvilles_joker
  [Tkinter] how to update label text from list Roshan 8 5,529 Apr-25-2020, 08:04 AM
Last Post: Roshan
  Update a label text from subprocess jim53 3 4,405 Aug-19-2019, 08:21 PM
Last Post: Denni
  Unable to update or refresh label text in tkinter jenkins43 3 6,712 Jul-24-2019, 02:09 PM
Last Post: Friend
  Display and update the label text which display the serial value jenkins43 5 9,162 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  [Tkinter] can't update label to include variable foxtreat 2 3,699 Dec-01-2018, 07:16 AM
Last Post: jfong

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020