Ttk主题设置

时间:2015-10-06 18:33:51

标签: python python-3.x tkinter ttk

试图改变Checkbutton的风格,我只是好奇它是否可以改变盒子本身的大小?

这是我到目前为止所拥有的。在配置部分尝试了“高度”和“宽度”,但似乎没有把它拿起来。

    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')]
              }
          }
       })

这可能吗?

谢谢!

1 个答案:

答案 0 :(得分:2)

ttk中的指标元素支持backgroundborderwidthindicatorcolorindicatorreliefindicatordiameterindicatormargin。这些都是使用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)复制到新样式中,然后覆盖自定义样式的指示符大小。

example of a standard and customised checkbutton

请注意,对于使用未由Tk绘制的指标元素的主题,将不支持此主题。例如,Windows主题的指示元素由Visual Styles API提供,其大小由系统定义的主题引擎确定。您可以从'默认值'中导入指标元素。如果你必须启用这种主题自定义,但是以使得应用程序的某些部分在该平台上看起来很奇怪,因为UI的外观和感觉开始不匹配而成为windows主题的主题。