Search code examples
pythontkinterindexingtreeview

when delete treeview row of python tkinter, how can i make in order number in treeview column


it is the problem i faced

i make treeview, with function of insert and delete

insert is act well, but delete is not.

i want to modify the number of no. when i delete treeview row

i make it in order as 1,2,3,4,5,6

please help me

enter image description here

enter image description here

please help me

pin_position_tree.index(selected_position) other method


Solution

  • Assuming your no. column is the first column in your Treeview, you can update the numbering of your rows with the following code

    my_treeview = ttk.Treeview()  # Replace this with your own treeview...
    for i, item in enumerate(my_treeview.get_children(''), 1):
        my_treeview.set(item, 0, i)