Tkinter小部件和/或系统默认颜色



我正在尝试实现一个tkinter小部件,它具有与Listbox类似的(最低(功能,但允许多行条目
基本上,它继承自Frame,管理自己的滚动行为,并且每个项目都是该帧中的Message

为了得到合理的外观&感觉,当点击一个项目时,我希望它能像用户期望的那样突出显示。

有没有一种很好的方法可以将系统/小部件的默认颜色用于此类任务
我发现这个页面,它向我表明,系统颜色取决于平台。这是正确的吗?或者有没有一种引用";正常高亮颜色";独立操作系统?

或者我应该手动实现颜色,这在我正在开发的系统上可能看起来很好,但在其他系统上很可能看起来很难看,或者至少不是有机的?

最简单的解决方案是创建一个临时列表框,然后让tkinter告诉你它使用的是什么颜色。

listbox = tk.Listbox(root)
colors = {attr: listbox.cget(attr) for attr in (
"background", "foreground", "disabledforeground",
"highlightbackground", "highlightcolor",
"selectbackground", "selectforeground"
)}

以上内容将生成列表框使用的颜色选项词典。在我的OSX盒子上,它返回这样的东西:

{
'background': 'systemTextBackgroundColor',
'disabledforeground': '#a3a3a3',
'foreground': 'systemTextColor',
'highlightbackground': 'systemWindowBackgroundColor',
'highlightcolor': 'Black',
'selectbackground': 'systemSelectedTextBackgroundColor',
'selectforeground': 'systemSelectedTextColor'
}

最新更新