Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6589135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:08:02+00:00 2026-05-25T17:08:02+00:00

I’m very new to programming and I just can’t figure out how to make

  • 0

I’m very new to programming and I just can’t figure out how to make this work for me…

I’m just trying to figure out how to extract the values from the treeview’s col4 into a function that would allow me to provide a simple sum in the result_display label at the bottom.

From what I’ve read, I need to use the item method on the treeview itself, but I can’t figure out how to reference it properly.

I’ve tried just dumping ANY value from the treeview into a test label using various command configurations, but none have produced anything more than an error.

Basically, I want the user to be able to hit the results button, to call the fullcalc function which will extract the values in col4, add them up and dump that sum into the result_display label using the endresult textvariable.

am I way off base here?

I’d appreciate any insight you can give me to tinker with.

import tkinter
from tkinter import *
from tkinter import ttk

### PRIMARY WINDOW AND FRAME ELEMENTS
root = Tk()
root.title('Calorie Counter')
entryframe = ttk.Frame(root, padding='10 10 10 10').grid(column=0, row=0)
listframe = ttk.Frame(root, padding='10 10 10 10').grid(column=0, row=3)
resultframe = ttk.Frame(root, padding='10 10 10 10').grid(column=0, row=6)

### GLOBAL VARIABLES
namevar = StringVar()
calentvar = DoubleVar()
volentvar = DoubleVar()
usedentvar = DoubleVar()
calinvar = DoubleVar()
uomvar = StringVar()
endresult = IntVar()


### FUNCTIONS
def itemadd():
    try:
        c0 = namevar.get()
        c2 = usedentvar.get()
        c3 = calinvar.get()
        f1 = volentvar.get()
        f2 = calentvar.get()
        cpv = f2 // f1

        tv.insert("",0,text=c0, values=(c0,cpv,c2,c3))
    except ValueError:
        pass

def itemremove():
    try:
        tv.delete(tv.focus())
    except ValueError:
        pass

def itemupdate(**args):
    try:
        a = calentvar.get()
        b = volentvar.get()
        c = (a / b)
        d = usedentvar.get()
        calinvar.set(c * d)
    except ValueError:
        pass

def fullcalc():
    try:
        pass
    except ValueError:
        pass


### ENTRY FRAME ELEMENTS
# Labels
name_label = ttk.Label(entryframe, text='Item Name').grid(column=0, row=0, columnspan=1)
calpervol_label = ttk.Label(entryframe, text='Calories  /  Volume').grid(column=1, row=0, columnspan=2)
uom_label = ttk.Label(entryframe, text='Unit of Measure').grid(column=3, row=0, columnspan=1)
used_label = ttk.Label(entryframe, text='Amount Used').grid(column=4, row=0, columnspan=1)
incal_label = ttk.Label(entryframe, text='Calories').grid(column=5, row=0, columnspan=1)

# Variable Entry/Display Elements
name_entry = ttk.Entry(entryframe, width=20, textvariable=namevar).grid(column=0, row=1, columnspan=1)
cal_entry = ttk.Entry(entryframe, width=12, textvariable=calentvar).grid(column=1, row=1, columnspan=1, sticky=(E))
vol_entry = ttk.Entry(entryframe, width=12, textvariable=volentvar).grid(column=2, row=1, columnspan=1, sticky=(W))
uom_combo = ttk.Combobox(entryframe, width=10, state='readonly', textvariable=uomvar, values=['grams', 'milliliters', 'teaspoons', 'tablespoons', 'cups']).grid(column=3, row=1, columnspan=1)
used_entry = ttk.Entry(entryframe, width=10, textvariable=usedentvar).grid(column=4, row=1, columnspan=1)
cal_label = ttk.Label(entryframe, width=10, textvariable=calinvar).grid(column=5, row=1, columnspan=1)

# Buttons
add_button = ttk.Button(entryframe, text='Add Item', command=itemadd).grid(column=0, row=2, columnspan=1, sticky=(E))
remove_button = ttk.Button(entryframe, text='Remove Item', command=itemremove).grid(column=1, row=2, columnspan=1, sticky=(W))
update_button = ttk.Button(entryframe, text='Calculate', command=itemupdate).grid(column=5, row=2, columnspan=1)


### LIST FRAME ELEMENTS
tv = ttk.Treeview(listframe, show='headings')
tv["columns"]=("col0", "col1","col2","col3")
tv.column("col0",width=100)
tv.column("col1",width=100,anchor="center" )
tv.column("col2",width=100)
tv.column("col3",width=100)
tv.heading("col0",text="Item")
tv.heading("col1",text="Calories per Volume")
tv.heading("col2",text="Volume Used")
tv.heading("col3",text="Calories Included")
tv.grid(column=0, row=3, columnspan=6)


### RESULT FRAME ELEMENTS
results = ttk.Button(resultframe, text='Calculate Total', command=fullcalc).grid(column=0, row=18)
results_label = ttk.Label(resultframe, text='Total Calories : ').grid(column=3, row=18)
results_display = ttk.Label(resultframe, textvariable=endresult)


### PROGRAM RUN ELEMENTS
root.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:08:03+00:00Added an answer on May 25, 2026 at 5:08 pm

    I am new to treeview, but I think I have your solution. This code will just show you how the values are “packaged” so you can use them however you like.

    def fullcalc():
       try:
          # get a list of children of the root node
          children = tv.get_children()
          for child in children:
              # For some odd reason the "set" method actually returns the values
              # if you're not actually setting something
              print(tv.set(child))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.