Skip to content
Advertisement

_tkinter.TclError: Item 1 already exists with tkinter treeview

I creating GUI interacting with treeview and I want to get all the value inside the list and show it in treeview window. I have a add button and once I click it, it will work fine. But on the second time, it shows an error Item 1 already exists. It also does not added to the list.

This is my code:

JavaScript

Traceback:

JavaScript

How do I refresh the treeview to reflect the changes made in the list?

Advertisement

Answer

Quick fix:

Get rid of the iid argument:

JavaScript

But that will create an issue of the No. column getting same value always.

Actual fix:

So the actual problem is your list contains alot of values, you should get rid of those values once you insert it, so the code should be something like:

JavaScript

This way your clearing whats inside of the list each time and appending new values to list. With your older code you can see that first time the the list is [('1', '1', '1', '1')] and when the next set of values is appended it becomes [('1', '1', '1', '1'), ('2', '2', '2', '2')] so there is not enough space accommodate all this value in? Anyway this fixes it. Or you could also make a tuple of those inputs and then pass that tuple as the values for treeview without looping, like acw1668 did.

Advertisement