如何自定义ttk.checkbutton颜色?
我正在寻找一种更改ttk.checkbutton tickbox的背景颜色(和活动颜色)的方法>
最佳的是,盒子的背景颜色应该匹配背景的颜色吗?
在style.configure()
方法中对此进行修改的命令是什么?
I am looking for a way to change the background color (and the active color) of the tickbox of the ttk.Checkbutton
Optimally, the background color of the box should match the background's color?
What is the command to modify this in the style.configure()
method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用选项
indodatorbackground
和incodatorforeground
更改tickbox的颜色。要更改活动颜色,您需要使用
style.map()
而不是style.configure()
。请注意,有了一些主题(例如OSX和Windows默认主题),以上命令不会产生任何效果,因为tickbox是用图像创建的。如果是这种情况,则可以更改使用的主题,例如,使用
style.theme_use(“ clam”)
,例如“ alt”或“ clam”。如果要继续使用不允许更改tickbox颜色的主题,则可以使用自己的tickbox映像:
我获得了
checkbutton
plinestyle.layout的布局(” tcheckbutton”)
,然后替换'checkbutton.indicator'
by'checkbutton.tickbox'
。It is possible to change the colors of the tickbox using the options
indicatorbackground
andindicatorforeground
.To change the active colors, you need to use
style.map()
instead ofstyle.configure()
.Note that with some themes (e.g. OSX and Windows default themes), the above commands do not produce any effect because the tickbox is created with an image. If this is the case, you can change the theme to use, for instance, "alt" or "clam", with
style.theme_use("clam")
.If you want to keep using a theme that does not allow to change the tickbox color, you can use your own tickbox images instead:
I obtained the layout of the
Checkbutton
withstyle.layout("TCheckbutton")
and then replaced'Checkbutton.indicator'
by'Checkbutton.tickbox'
.