Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove empty first column of a Treeview object

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

like image 606
Ashish Gaurav Avatar asked Dec 31 '11 15:12

Ashish Gaurav


2 Answers

A little bit late and hacky but what you also could do is:

tree.column("#0", width=0)

not forgetting to set the minimum width too to zero by using; tree.column("#0", minwidth="0")

'#0' is the identifier of the first column, so setting the width to 0 would technically hide it

like image 90
Brueni92 Avatar answered Oct 07 '22 05:10

Brueni92


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.

like image 43
Demosthenex Avatar answered Oct 07 '22 05:10

Demosthenex