在ttk.treeview中如何设置插入的文字颜色

import tkinter as tk
import tkinter.ttk as ttk


def center(main, width, height):
    screen_width = root.winfo_screenwidth()
    screen_height = root.winfo_screenheight()
    right_x = (screen_width - width)//2
    right_y = (screen_height - height) //2
    main.geometry(f'{width}x{height}+{right_x}+{right_y}')


root = tk.Tk()
root.title('treeview')
center(root, 600, 400)

tree = ttk.Treeview(root, show='tree')
parent1 = tree.insert('', 0, '广东', text='广东省', values=['1'])
tree.insert(parent1, 0, '广州', text='广东省广州市-0001', values=['2'])
tree.insert(parent1, 1, '深圳', text='广东省深圳市-0002', values=['3'])
parent1 = tree.insert('', 1, '福建', text='福建省', values=['4'])
tree.insert(parent1, 0, '漳州', text='福建省漳州市-0011', values=['5'])
tree.insert(parent1, 1, '厦门', text='福建省厦门市-0012', values=['6'])
tree.pack(fill='both', expand=True)
root.mainloop()

Jason990420
最佳答案

How to change color in a spesific cell in ttk treeview ?

You cannot change the color of a specific cell in the Treeview widget. Formatting can only be applied to entire rows. Colors can only be applied with tags, and tags can only be applied to an item as a whole, not a part of an item.

2个月前 评论
讨论数量: 1
Jason990420

How to change color in a spesific cell in ttk treeview ?

You cannot change the color of a specific cell in the Treeview widget. Formatting can only be applied to entire rows. Colors can only be applied with tags, and tags can only be applied to an item as a whole, not a part of an item.

2个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!