尝试更改Checkbutton的样式,我只是好奇是否可以更改框本身的大小?
这就是我到目前为止所拥有的。尝试了配置部分中的“height”和“width”,但似乎没有使用。
s = ttk.Style()
s.theme_use('default')
s.configure("cbutton.TCheckbutton", foreground='#ebebeb', background='#5c5c5c', font=("arial", 14))
s.theme_settings("default",
{"TCheckbutton": {
"configure": {"padding": 5},
"map": {
"background": [("active", "#5C5C5C"),("!disabled", "#5C5C5C")],
"fieldbackground": [("!disabled", "#5C5C5C")],
"foreground": [("focus", "lightgray"),("!disabled", "lightgray")], "indicatorcolor": [('selected','#9ac947'),('pressed','#9ac947')]
}
}
})这个是可能的吗?
谢谢!
发布于 2015-10-23 06:55:38
ttk中的indicator元素支持background、borderwidth、indicatorcolor、indicatorrelief、indicatordiameter和indicatormargin。这些都是使用小部件样式的style.configure()设置为主题配置值的。您可以通过更改indicatordiameter来更改Tk绘制主题的指示器元素的大小。例如:
style = ttk.Style()
style.layout('Custom.Checkbutton', style.layout('TCheckbutton'))
style.map('Custom.Checkbutton', **style.map('TCheckbutton'))
style.configure('Custom.Checkbutton', **style.configure('TCheckbutton'))
style.configure('Custom.Checkbutton', indicatordiameter='24')它将标准复选按钮样式(TCheckbutton)复制到新样式中,然后覆盖自定义样式的指示器大小。

请注意,对于使用不是由Tk绘制的指示器元素的主题,这将不受支持。例如,Windows主题的指示器元素由Visual Styles API提供,其大小由系统定义的主题引擎确定。如果你必须启用这种主题定制,你可以将一个indicator元素从默认的主题导入到windows主题中,但代价是让你的应用程序的某些部分在该平台上看起来很奇怪,因为UI的外观和感觉开始不匹配了。
https://stackoverflow.com/questions/32977148
复制相似问题