0

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")
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

1

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",))
        
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Isn't it weird that tcl splits up at space, I think if it was python, it would have iterated through the string 'Hello World' and got made 11 items? – Delrius Euphoria Dec 11 '20 at 22:10
  • 1
    @CoolCloud tkinter just passes what it was given to the underlying Tcl interpreter. Splitting on spaces in the Tcl interpreter is fundamental to that language. – Bryan Oakley Dec 11 '20 at 22:19