I am trying to use ttk.Treeview to create a sortable table (according to Does tkinter have a table widget? And https://www.daniweb.com/software-development/python/threads/350266/creating-table-in-python ).
Working with him is easy, but I am having problems with the style. The default style for the Treeview title is black text on a white background, and that's fine. However, in my code I use:
ttk.Style().configure(".", font=('Helvetica', 8), foreground="white")
to format my GUI. This comprehensive style also affects the title of the Treeview widget. Since the title bar is white by default, I donβt see the text (unless I find the mouse pointer over the title that turns it blue).
I usually redefine the style of the widget using a tag to change the background or foreground, but I canβt understand for life how to customize Treeview headers! ttk.Treeview (...) does not accept any tags, but ttk.Style (). configure ("Treeview", ...) has no effect. It seems that only Treeview elements accept tags when using widget.insert (...).
This is confusing to me because comprehensive ttk.Style (). configure (".", ...) affects Treeview headers, so you can apply a tag to them.
Does anyone know how to change the title style of a Treeview?
Below is a minimal working example. Note that the tag works for elements, but not for headers, that the Treeview style has no effect and that "." style has an effect. I am using Python 2.7 for Windows 7 if that matters.
from Tkinter import * import ttk header = ['car', 'repair'] data = [ ('Hyundai', 'brakes') , ('Honda', 'light') , ('Lexus', 'battery') , ('Benz', 'wiper') , ('Ford', 'tire')] root = Tk() frame = ttk.Frame(root) frame.pack() table = ttk.Treeview(frame, columns=header, show="headings") table.pack()