Remove empty first column of a Treeview object

Ashish Gaurav picture Ashish Gaurav · Dec 31, 2011 · Viewed 13.8k times · Source

I'm trying to make a program that retrieves records from a database using sqlite3, and then display them using a Treeview.

I succeeded in having a table created with the records, but I just can't remove the first empty column.

def executethiscommand(search_str):
    comm.execute(search_str)
    records = comm.fetchall()
    rows = records.__len__()
    columns = records[0].__len__()

    win = Toplevel()
    list_columns = [columnames[0] for columnames in comm.description]
    tree = ttk.Treeview(win)
    tree['columns'] = list_columns

    for column in list_columns:
        tree.column(column, width=70)
        tree.heading(column, text=column.capitalize())

    for record in records:
        tree.insert("", 0, text="", values=record)

    tree.pack(side=TOP, fill=X)

enter image description here

Answer

Demosthenex picture Demosthenex · Jan 5, 2012

That first empty column is the identifier of the item, you can suppress that by setting the show parameter.

t = ttk.Treeview(w)
t['show'] = 'headings'

That will eliminate that empty column.