10

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!

patthoyts
  • 32,320
  • 3
  • 62
  • 93
Scribble_Scratch
  • 403
  • 3
  • 18
  • I don't know for sure, but I don't think so. I've looked through the online docs and through "Tcl and the Tk Toolkit" second edition, and I can't find anything that looks like resizing the checkbox itself. – saulspatz Oct 07 '15 at 06:45
  • As you can read in [the Docs]http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_checkbutton.htm#M10 the width and height are used to specify space to be available for the text of the Checkbutton Widget. There is unfortunately nothing you can do on the Checkbutton style to directly scale it up. You can imitate it by creating a new Checkbutton widget on your own (e.g. based on the Frame or Button Widget) and set the background image to a empty or selected checkbutton image to achieve that. – R4PH43L Oct 07 '15 at 12:02
  • Good to know -- thanks! – Scribble_Scratch Oct 07 '15 at 15:59

1 Answers1

5

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.

example of a standard and customised checkbutton

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.

patthoyts
  • 32,320
  • 3
  • 62
  • 93