Skip to content
Advertisement

Tkinter : How to add multiple columns in a treeview and avoid typeError

I am trying to create a Treeview with a lot of columns.

Here is my class that create the window with the treeview :

JavaScript

I have this error when I run it : TypeError: can only concatenate str (not “tuple”) to str

I know that there is a problem with my type, and the error say that this error happen here : line 57, in init self.param = self.tree[“columns”] + (str(self.k),)

To avoid this error i tried to add the str notation but that didnt worked.

Advertisement

Answer

Since you create self.tree with empty tuple as the columns option, the return value of self.tree["columns"] is an empty string instead of empty tuple. You can verify it by printing the type of self.tree["columns"] after the creation of self.tree. That’s why exception is raised on the mentioned line.

Actually you can simplify the following for loop:

JavaScript

by

JavaScript

Also I think that the for self.j in range(50) in the following for loop

JavaScript

should be for self.k in range(50) instead.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement