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!
We can change the height of the ttk button by using the grid(options) method. This method contains various attributes and properties with some different options. If we want to resize the ttk button, we can specify the value of internal padding such as ipadx and ipady.
Tkinter widgets are used to add Buttons, Labels, Text, ScrollBar, etc., however, tkinter. ttk supports a variety of widgets as compared to tkinter widgets. Tkinter. ttk doesn't support Place, Pack() and Grid(), thus it is recommended to use tkinter widget with ttk.
There are no options to style it the same way if you could use CSS. I recently reported to their bug tracker to consider this - at the least to support the same (limited) subset that gtk3 supports, e. g. margin, padding, border, colours.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With