Ttk主题设置

2024-10-02 14:19:46 发布

您现在位置:Python中文网/ 问答频道 /正文

试图改变一个Checkbutton的样式,我只是好奇是否有可能改变方框本身的大小?在

这就是我目前所拥有的。尝试了configure部分中的'height'和'width',但似乎找不到。在

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

这可能吗?在

谢谢!在


Tags: defaultstyleconfigure样式widththemebackgroundttk
1条回答
网友
1楼 · 发布于 2024-10-02 14:19:46

ttk中的指示符元素支持backgroundborderwidthindicatorcolorindicatorreliefindicatordiameter和{}。这些都被设置为使用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')

它将标准checkbutton样式(TCheckbutton)复制到新样式中,然后覆盖自定义样式的指示器大小。在

example of a standard and customised checkbutton

注意,对于使用不是由Tk绘制的指示符元素的主题,这将不受支持。例如,Windows主题的指示符元素是由视觉样式API提供的,它的大小由系统定义的主题引擎决定。如果必须启用这种主题自定义,则可以将指示符元素从“默认”主题导入到windows主题中,但代价是使应用程序的某些部分在该平台上看起来奇怪,因为UI的外观开始不匹配。在

相关问题 更多 >