0

I have the following code for a ttk Treeview:

listbox = ttk.Treeview(
    tab_player,
    columns=('Player', 'Rating', 'Price'),
    selectmode="extended",
)

listbox.heading('#0', text='Player', anchor=tk.CENTER)
listbox.heading('#1', text='Rating', anchor=tk.CENTER)
listbox.heading('#2', text='Price', anchor=tk.CENTER)
listbox.column('#0', stretch=tk.YES, minwidth=50, width=80)
listbox.column('#1', stretch=tk.YES, minwidth=50, width=20)
listbox.column('#2', stretch=tk.YES, minwidth=50, width=30)

listbox.grid(row=5, column=5, rowspan=7, sticky=W)

My insert function is as follows:

def insertitem():
        GUI.listbox.insert('', 'end', values = (GUI.listbox_content.get(), 
                                                GUI.listboxr_content.get(), 
                                                GUI.listbox_content_price.get()))

When I launch my app, I have one additional column and the inserted data is not as I want (data in wrong columns).

enter image description here

Why is that?

1 Answer 1

1

Column "#0" always refers to the tree column, not for data columns. So use "#1", "#2", "#3" instead and set show="headings" to hide the tree column:

listbox = ttk.Treeview(
    tab_player,
    columns=('Player', 'Rating', 'Price'),
    selectmode="extended",
    show="headings"  # hide the tree column
)

listbox.heading('#1', text='Player', anchor=tk.CENTER)
listbox.heading('#2', text='Rating', anchor=tk.CENTER)
listbox.heading('#3', text='Price', anchor=tk.CENTER)

listbox.column('#1', stretch=tk.YES, minwidth=50, width=80)
listbox.column('#2', stretch=tk.YES, minwidth=50, width=60)
listbox.column('#3', stretch=tk.YES, minwidth=50, width=60)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.