Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ttk Theme Settings

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!

like image 520
Scribble_Scratch Avatar asked Oct 06 '15 18:10

Scribble_Scratch


People also ask

How do I change the size of my TTK button?

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.

What is the difference between Tk and TTK?

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.

Can you style tkinter with CSS?

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.


1 Answers

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.

like image 170
patthoyts Avatar answered Sep 22 '22 12:09

patthoyts