本文用于个人学习记录。
经查验,主要原因可能是“在Tkinter 8.6.9中,Treeview样式被破坏。”
解决方法:经借鉴,修复Treeview属性,并更换style。代码如下:
# -----修复函数-----
def fixed_map(self, option):
# Fix for setting text colour for Tkinter8.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 listfor missing options, so this
# should be future-safe.
style = Style()
return [elm for elm in style.map('Treeview', query_opt=option) if
elm[:2] != ('!disabled', '!selected')]
# -----使用时,调用修复函数-----
style = Style(self)
# set ttk theme to "clam" which support the fieldbackground option
style.theme_use("winnative")
style.map('Treeview', foreground=self.fixed_map('foreground'),
background=self.fixed_map('background'))
style.configure("Treeview", background="#EFF2F8", foreground="black", fieldbackground="#EFF2F8")
self.tree1 = Treeview(self.right1, columns=('a', 'd'))