I have a Tkinter Treeview with a header row. I am using the following style to style the header.
style = tk.ttk.Style()
style.theme_use('clam')
style.configure('Treeview.Heading', font=('Calibri', 10,'bold'))
style.map('Treeview', background=[('selected', 'blue')])
But I want the table to have just a title saying "INVOICES" and I do not want the separators in the header separating the columns, as seen in the photo below.
Is there a way to get rid of these separators?
Bonus points if you you can help me get the scrollbar to actually look like a scrollbar instead of being full (there are over 100 records in this test table).
Here is the rest of the code to place the treeview into a frame.
self.invoice_frame = tk.Frame(self, border=1, relief=tk.GROOVE, bg='white')
self.invoice_frame.place(relx=0.3, rely=row_3_top, relwidth=0.3425, relheight=0.3)
self.invoice_tree = tk.ttk.Treeview(self.invoice_frame, column=('c1', 'c2', 'c3'), show='headings')
self.invoice_tree.pack(side='left', fill='both', expand=True)
tree_scrollbar = tk.ttk.Scrollbar(self.invoice_frame, orient='vertical', command=self.invoice_tree.yview)
tree_scrollbar.pack(side='right', fill='y')
self.invoice_tree.column('c1', minwidth=40, width=100, anchor=tk.CENTER)
self.invoice_tree.heading('c1', text='')
self.invoice_tree.column('c2', minwidth=40, width=100, anchor=tk.CENTER)
self.invoice_tree.heading('c2', text='INVOICES')
self.invoice_tree.column('c3', minwidth=40, width=100, anchor=tk.CENTER)
self.invoice_tree.heading('c3', text='')
# adding random info
contacts = []
for n in range(1,100):
contacts.append((f'first {n}', f'last {n}', f'test{n}'))
for contact in contacts:
self.invoice_tree.insert('', tk.END, values=contact)
Thanks
CodePudding user response:
You can set the relief
style option to none
to remove the separators.
style.configure('Treeview.Heading', font=('Calibri', 10,'bold'), relief='none')
For the scrollbar issue, you need to configure yscrollcommand
option of the treeview:
self.invoice_tree.config(yscrollcommand=tree_scrollbar.set)