since I re-build the database from SQLite DB Browser and make the connection to Tkinter treeview again, the columns and headings in tkinter treeview does not align with the data inserted in the table. Please help me look closely if I have anything wrong with my code. Much Appreciated.
self.tree = ttk.Treeview(self.frm_main)
self.tree.configure(yscrollcommand=self.yscrollbar.set, xscrollcommand=self.xscrollbar.set)
self.yscrollbar.configure(command=self.tree.yview)
self.xscrollbar.configure(command=self.tree.xview)
self.yscrollbar.pack(side=tk.RIGHT, fill=tk.Y)
self.xscrollbar.pack(side=tk.BOTTOM, fill=tk.X)
self.tree.configure(selectmode="extended")
self.tree['columns'] = ('title', 'keywords', 'author', 'year')
#self.tree['show'] = 'headings'
self.tree.column('#0', width=0, stretch=tk.NO) # hide the first column
self.tree.column('title', width=300, stretch=True, anchor=tk.W)
self.tree.column('keywords', width=300, stretch=True, anchor=tk.W)
self.tree.column('author', width=200, stretch=True, anchor=tk.W)
self.tree.column('year', width=80, stretch=True, anchor=tk.CENTER)
self.tree.heading('#0', text='') # hide the first column.
self.tree.heading('title', text='Title', anchor=tk.CENTER)
self.tree.heading('keywords', text='Keywords', anchor=tk.CENTER)
self.tree.heading('author', text='Author', anchor=tk.CENTER)
self.tree.heading('year', text='Year', anchor=tk.CENTER)
self.tree.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.YES, anchor=tk.NW)
Below is the function: #view all data from the database. def viewall(self): print("view all") #self.tree.delete(0, tk.END) be = backend("title","keywords","author","year","rows") #create backend objects for row in be.viewall(): self.tree.insert('', tk.END, values=row[1:])
That is the back-end connection part: #View all data and connection to the database. def viewall(self): self.conn = sql.connect("C:\Findr\Tkinter_App\DB_Folder\conferencefile.db") print(self.conn) self.cur = self.conn.cursor() print(self.cur) self.cur.execute("SELECT * FROM papers") rows = self.cur.fetchall() for row in rows: print(row) self.conn.close() return rows
