Search code examples
pythondictionarytreeview

How to retrieve data from dict in Python?


When I click on a treeview item it outputs

{'text': 1, 'image': '', 'values': [1, '3:18:00', 'pm'], 'open': 0, 'tags': ''}

How do I retrieve the specific values like the 1 or pm ? I used


    queryResultTable.bind('<ButtonRelease-1>', select_item)

    def select_item(a):
        itemlibrary = queryResultTable.focus()
        print(queryResultTable.item(itemlibrary))

I tried .get but couldn't really get anywhere


Solution

  • Try this:

    a = {'text': 1, 'image': '', 'values': [1, '3:18:00', 'pm'], 'open': 0, 'tags': ''}
    print(a['values'][0])
    print(a['values'][2])
    

    This should give you:

    1
    pm