解决Tkinter中Treeview设置background报错问题

本文用于个人学习记录。

经查验,主要原因可能是“在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'))

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值