Mat*_*ick 33
几个月前我也有同样的问题.
来自tk文档:
You can assign a list of tags to each item using the "tags"
item configuration option (again, when creating the item or later on).
Tag configuration options can then be specified, which will then
apply to all items having that tag.
Run Code Online (Sandbox Code Playgroud)
基本上,您将一个标记应用于所有奇数行,为每个偶数行应用不同的标记,然后配置标记.
在树视图中创建项目时,向其添加标记:
tree.insert('', 'end', text = 'your text', tags = ('oddrow',))
Run Code Online (Sandbox Code Playgroud)
此代码在其中创建一个元素tree
,并且该tags
参数将标记'oddrow'分配给该元素.
使用'oddrow'和'evenrow'标签创建所有元素后,您可以为标记着色:
tree.tag_configure('oddrow', background='orange')
tree.tag_configure('evenrow', background='purple')
Run Code Online (Sandbox Code Playgroud)