Search code examples
pythontkinterwidgettreeviewtk-toolkit

Are you only allowed one word with Treeview values?


I might be missing something completely obvious here as I am completely new to Treeview, but when I insert my values ("Hello there" in this case), only the "Hello" outputs - it is always only the first word that appears...

As you can probably see, I am trying to make a pros and cons table with fixed values but I think you have to have a "#0" column, so I have ended up making this my "Pros" column - is this the best way to do things?

symmetric_tree=ttk.Treeview(symmetric_tab)

symmetric_tree["columns"]=("one")
symmetric_tree.column("#0", width=270, minwidth=270)
symmetric_tree.column("one", width=150, minwidth=150)

symmetric_tree.heading("#0",text="Pros",anchor=W)
symmetric_tree.heading("one", text="Cons",anchor=E)

symmetric_tree.insert(parent="", index="end", iid="#0", text="Easy to implement", 
                      values=("Hello there"))

symmetric_tree.pack(side="top",fill="x")

Solution

  • The treeview method requires you pass a list or tuple of values. You're passing a single value. Since it's not a list, the internal tcl interpreter converts the value to a list by splitting on spaces.

    The solution is to pass a list or tuple to insert. Note that ("Hello there") is a single value, ("Hello there",) is a tuple with a single value.

    symmetric_tree.insert(..., values=("Hello there",))