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)
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With