Python 如何正确设置treeview行的前景色和背景色

Python 如何正确设置treeview行的前景色和背景色,python,tkinter,Python,Tkinter,我在设置ttk.Treeview的前景色和背景色时遇到问题 我尝试过使用tag_configure,但似乎也不起作用。我有一些模型代码(如下),我正在使用它来解决这个问题。 可以更改标题颜色,但不能更改行,不确定我做错了什么 from tkinter import * from tkinter.ttk import Treeview, Style class App(Frame): def __init__(self, parent): super().__init

我在设置ttk.Treeview的前景色和背景色时遇到问题

我尝试过使用tag_configure,但似乎也不起作用。我有一些模型代码(如下),我正在使用它来解决这个问题。 可以更改标题颜色,但不能更改行,不确定我做错了什么

from tkinter import *
from tkinter.ttk import Treeview, Style


class App(Frame):

    def __init__(self, parent):
        super().__init__()
        self.container = Frame.__init__(self, parent)

        self.tree()

    def tree(self):
        style = Style()

        tv = Treeview(self.container)
        tv.grid(sticky='NSEW')

        tv.insert('', '0', 'item1', text='Item 1', tags='row')
        tv.insert('', '1', 'item2', text='Item 2', tags='row')
        tv.insert('', '2', 'item3', text='Item 3', tags='row')

        tv.insert('item1', '0', 'python1', text='Python Treeview1')
        tv.insert('item1', '1', 'python2', text='Python Treeview2')

        tv.insert('python1', '0', 'thon1', text='Treeview1')
        tv.insert('python1', '1', 'thon2', text='Treeview2')

        tv.heading(f'#{0}',  text='Title')
        style.configure(
            "Treeview.Heading",
            padding=5,
            borderwidth=0,
        )

        style.configure(
            "Treeview",
            foreground='red',
            background="black",
            fieldbackground='blue'
        )
        tv.tag_configure('row', foreground='red')


def main():
    root = Tk()

    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)
    App(root)

    root.mainloop()


if __name__ == '__main__':
    main()

Tcl/tk库中有一个bug,如中的注释所述。

Read Nothing(无任何帮助)仍然无法将树行从白色背景上的黑色文本更改为白色。我知道有一个名为tag_configure()的方法。我用它来尝试改变颜色,但没有运气。我看过其他帖子,它们似乎指向tag_configure()。感谢您的回复。您必须在
tv=Treeview(…
之前进行
style.configure(…
这可能与感谢您有关。我从您发送给我的链接中找到了修复程序。