Issue36468
Created on 2019-03-29 08:31 by guillaumeb, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| 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 | |
Hello,
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) * ![]() |
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 python.org 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()
root.tk.call('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:
https://core.tcl.tk/tk/info/509cafafae
|
|||
| msg342678 - (view) | Author: Matthew Barnett (mrabarnett) * ![]() |
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: https://core.tcl.tk/tk/info/509cafafae
#
# Returns the style map for 'option' with any styles starting with
# ('!disabled', '!selected', ...) filtered out.
# style.map() returns an empty list for missing options, so this
# should be future-safe.
return [elm for elm in style.map('Treeview', query_opt=option) if
elm[:2] != ('!disabled', '!selected')]
style = ttk.Style()
style.map('Treeview', foreground=fixed_map('foreground'),
background=fixed_map('background'))
|
|||
| msg362551 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
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. https://docs.python.org/3.9/whatsnew/changelog.html#python-3-9-0-beta-3 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. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:13 | admin | set | github: 80649 |
| 2020-06-29 11:49:55 | PySimpleGUI | set | nosy:
+ PySimpleGUI messages: + msg372564 |
| 2020-02-24 00:23:57 | terry.reedy | set | nosy:
+ terry.reedy messages:
+ msg362551 |
| 2019-11-28 06:38:05 | ned.deily | link | issue38917 superseder |
| 2019-07-10 14:54:21 | ned.deily | link | issue37546 superseder |
| 2019-05-16 23:20:50 | mrabarnett | set | nosy:
+ mrabarnett messages: + msg342678 |
| 2019-03-29 20:33:08 | ned.deily | set | status: open -> closed nosy:
+ ned.deily resolution: third party |
| 2019-03-29 10:54:41 | SilentGhost | set | nosy:
+ gpolo, serhiy.storchaka |
| 2019-03-29 08:31:58 | guillaumeb | create | |

