Reputation: 403
Trying to change the style of a Checkbutton and I'm just curious if its possible to change the size of the box itself?
This is what I have so far. Tried 'height' and 'width' in the configure section but doesn't seem to pick it up.
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')]
}
}
})
Is this possible?
Thanks!
Upvotes: 10
Views: 2127
Reputation: 33223
The indicator element in ttk supports background
, borderwidth
, indicatorcolor
, indicatorrelief
, indicatordiameter
and indicatormargin
. These are all set as theme configuration values using style.configure()
for the widget style. You can change the size of the indicator element for the Tk drawn themes by changing the indicatordiameter
. eg:
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')
which copies the standard checkbutton style (TCheckbutton) into a new style then overrides the indicator size for the custom style.
Note that for themes that use an indicator element that is not drawn by Tk this will not be supported. For instance the indicator element for Windows themes is provided by the Visual Styles API and it's size is determined by the system defined themeing engine. You can import an indicator element from the 'default' theme into the windows theme if you have to to enable this kind of theme customisation but at the cost of making parts of your application look strange on that platform as the UI look and feel starts to be mismatched.
Upvotes: 5