Title: Treeview: wrong color change
Type: behavior Stage: resolved
Components: Tkinter Versions: Python 3.9, Python 3.8, Python 3.7
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: PySimpleGUI, gpolo, guillaumeb, mrabarnett, ned.deily, serhiy.storchaka, terry.reedy
Priority: normal Keywords:

Created on 2019-03-29 08:31 by guillaumeb, last changed 2020-06-29 11:49 by PySimpleGUI. This issue is now closed.

File name Uploaded Description Edit
test_treeview_color.png guillaumeb, 2019-03-29 08:31 Treeview difference between Python v3.7.2 and v3.7.3
Messages (5)
msg339101 - (view) Author: Burgunder (guillaumeb) Date: 2019-03-29 08:31
color change with Treeview does not work in Python 3.7.3,
but it works with Python 3.7.2.

Test code:
# -*- coding: utf-8 -*-
import tkinter
from tkinter import ttk
root = tkinter.Tk ()
style = ttk.Style (root)
style.configure ("Treeview", foreground="yellow", background="grey", fieldbackground="green")
tree = ttk.Treeview (root, columns=('Data'))
tree.heading ('#0', text='Item')
tree.heading ('#1', text='Data')
tree.insert ("", "end", text="Item_0", values=100, tags="A")
tree.insert ("", "end", text="Item_1", values=200, tags="B")
tree.insert ("", "end", text="Item_2", values=300, tags="C")
tree.tag_configure ("A", foreground="black") #Py 3.7.3: no effect
tree.tag_configure ("B", foreground="red")
tree.pack ()
root.mainloop ()
msg339142 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-03-29 20:33
Thanks for the report.  The difference in behavior appears to be due to a change in Tk. Using the 3.7.2 or .3 installers which use Tk 8.6.8, the colors are displayed.  But if I use a Python linked with Tk 8.6.9, the bars are not colored.  You can run the following commands in Python to verify which version of Tk is in use:

import tkinter
root = tkinter.Tk()'info', 'patchlevel')

In any case, there isn't likely anything Python can do about it as tkinter is pretty much a thin wrapper around calls to Tk and it's difficult to know what the expected Tk behavior is.  If you want to pursue this issue, I suggest bringing it up on a Tk forum or checking whether there is a Tk issue about it.

But I had luck! Doing a quick search, I found this Tk ticket which seems to describe your problem and does confirm that the behavior change was introduced in 8.6.9:
msg342678 - (view) Author: Matthew Barnett (mrabarnett) * (Python triager) Date: 2019-05-16 23:20
I've just come across the same problem.

For future reference, adding the following code before using a Treeview widget will fix the problem:

def fixed_map(option):
    # Fix for setting text colour for Tkinter 8.6.9
    # From:
    # Returns the style map for 'option' with any styles starting with
    # ('!disabled', '!selected', ...) filtered out.

    # returns an empty list for missing options, so this
    # should be future-safe.
    return [elm for elm in'Treeview', query_opt=option) if
      elm[:2] != ('!disabled', '!selected')]

style = ttk.Style()'Treeview', foreground=fixed_map('foreground'),
msg362551 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-02-24 00:23
I verified that problem continues on Windows with 3.8 and 3.9 alpha (with tk 8.6.9 -- might get updated later) and that fix posted by Matthew works.  I am testing because of #39636.
msg372564 - (view) Author: PySimpleGUI (PySimpleGUI) Date: 2020-06-29 11:49
The tk project fixed this problem in release 8.6.10.

I don't see where this version of tk is being picked up.  The release notes of 3.9.0 Beta3 show tk version 8.6.9 is being used for Windows.

Is there a planned release vehicle for 8.6.10?  How does tk integration get into a Python release?

It would be nice to know what version of Python users should be on the lookout for in order to get this fix.
Date User Action Args
2020-06-29 11:49:55PySimpleGUIsetnosy: + PySimpleGUI
messages: + msg372564
2020-02-24 00:23:57terry.reedysetnosy: + terry.reedy

messages: + msg362551
versions: + Python 3.8, Python 3.9
2019-11-28 06:38:05ned.deilylinkissue38917 superseder
2019-07-10 14:54:21ned.deilylinkissue37546 superseder
2019-05-16 23:20:50mrabarnettsetnosy: + mrabarnett
messages: + msg342678
2019-03-29 20:33:08ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg339142

resolution: third party
stage: resolved
2019-03-29 10:54:41SilentGhostsetnosy: + gpolo, serhiy.storchaka
2019-03-29 08:31:58guillaumebcreate