Skip to content Skip to sidebar Skip to footer

Printing And Inserting Selected Row In Treeview Into Tkinter Entry Widget

I have the following code to print and insert selected treeview row in anentry widget but am having challenges on how to do it.My List profile doesn't display the content correctly

Solution 1:

First of all, you need to iterate over your profile list to populate the treeview:

forvaluesin profile:
    tree.insert("", END, values=values)

What you were doing:

tree.insert("", 1, END, values=profile)

created one row, with item name 'end' and values the first two tuple of profile.

I guess that you want to insert the year of the selected row in e1 and the month in e2. However, tree.selection() gives you the selected items' name, not the values, but you can get them with year, month = tree.item(nm, 'values'). So the content function becomes

def content(event):
    print(tree.selection()) # this will print the names of the selected rows

    for nm in tree.selection():
        year, month = tree.item(nm, 'values')
        e1.insert(END, year)
        e2.insert(END, month)

Post a Comment for "Printing And Inserting Selected Row In Treeview Into Tkinter Entry Widget"