I am trying to use tkinter to display information from a MongoDB database. However all of the different db columns are being returned in a single column rather than the correct db column. The column headings are displayed correctly and all of the data is there when I expand the column it is displayed in. Here is the relevant code:
columns = list(df.columns.values) tree = ttk.Treeview(window, columns=columns, show='headings') for column in columns: tree.heading(column, text=column) for row in rows: tree.insert("", tk.end, values=row)
If I change the insert line to this I then get the column headings being displayed recursively in each column but no actual row data:
tree.insert("", tk.END, values=list(row))
I have looked and looked but cant work out what I am doing wrong and most examples don't involve getting data from a MongoDB database.
If I change the code to this below and miss out the database connection this works fine:
columns = ('BUSINESS ID', 'BUSINESS NAME', 'ORDERS') tree = ttk.Treeview(window, columns=columns, show='headings') for column in columns: tree.heading(column, text=column) rows = [] for n in range(1, 100): rows.append((f'id {n}', f'name {n}', f'orders {n}')) for row in rows: tree.insert('', tk.END, values=row)
https://stackoverflow.com/questions/65666381/tkinter-returning-all-database-columns-in-one-column January 11, 2021 at 07:52PM
没有评论:
发表评论