首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ttk主题设置

Ttk主题设置
EN

Stack Overflow用户
提问于 2015-10-07 02:33:51
回答 1查看 1.7K关注 0票数 8

尝试更改Checkbutton的样式,我只是好奇是否可以更改框本身的大小?

这就是我到目前为止所拥有的。尝试了配置部分中的“height”和“width”,但似乎没有使用。

代码语言:javascript
复制
    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')]
              }
          }
       })

这个是可能的吗?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2015-10-23 06:55:38

ttk中的indicator元素支持backgroundborderwidthindicatorcolorindicatorreliefindicatordiameterindicatormargin。这些都是使用小部件样式的style.configure()设置为主题配置值的。您可以通过更改indicatordiameter来更改Tk绘制主题的指示器元素的大小。例如:

代码语言:javascript
复制
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)复制到新样式中,然后覆盖自定义样式的指示器大小。

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32977148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档