tcl中的按钮是否有一种全局风格?

tcl中的按钮是否有一种全局风格?,tcl,Tcl,所以我有这种类型的按钮和这个选项 button .but1 -text "Sample" -width 10 -height 2 -background $btnColor -activeforeground $actForegrd -state normal -activebackground $activbtnColor -relief flat -highlightthickness 0 是否有一种方法可以使用这些按钮选项生成全局变量,我知道样式配置,但为了使用样式,我需要将我的按钮更改

所以我有这种类型的按钮和这个选项

button .but1 -text "Sample" -width 10 -height 2 -background $btnColor -activeforeground $actForegrd -state normal -activebackground $activbtnColor -relief flat -highlightthickness 0
是否有一种方法可以使用这些按钮选项生成全局变量,我知道样式配置,但为了使用样式,我需要将我的按钮更改为ttk::button,而这些按钮的选项与常规按钮不同

我尝试将所有选项放在一个字符串中,并在创建按钮时传递它,但它不起作用 例如:


有两种基本的可能性

1.使用扩展 你所尝试的几乎是对的。试试这个:

set style "-width 10 -height 2 -background $btnColor -activeforeground $actForegrd -state normal -activebackground $activbtnColor -relief flat -highlightthickness 0"
button .but1 {*}$style
{*}
(在8.5中输入了Tcl)使它后面的内容扩展为许多参数

2.使用“数据库”选项 相反,您可以使用以下命令将所有这些值放入选项数据库:

正确地使用选项数据库是很棘手的,但它允许您同时设置多个小部件的默认值(或单个小部件,或只是某个特定窗口的子部件,或某个窗口类的子部件,或…),您将真正地从代码中分离样式

不过,我通常不会让这个机制设置
状态
,因为这更像是一个语义选项;如果一个按钮将被禁用或不被禁用,这对代码来说真的很重要(就像发生这种情况时运行的回调是另一个我没有通过选项设置的回调一样)


应该注意的是,Ttk样式/主题机制在很大程度上取代了这一机制,因为它允许进行更实质性的修改并在它们之间进行更干净的运行时切换。但是有很多效果是很难做到的;出于某种原因,我们仍然保留经典的
按钮
,等等

set style "-width 10 -height 2 -background $btnColor -activeforeground $actForegrd -state normal -activebackground $activbtnColor -relief flat -highlightthickness 0"
button .but1 {*}$style
option add *.Button.width 10
option add *.Button.height 2
option add *.Button.background $btnColor
option add *.Button.activeForeground $actForegrd
option add *.Button.state normal
option add *.Button.activeBackground $activbtnColor
option add *.Button.relief flat
option add *.Button.highlightThickness 10
## You can also pull the above from a separate file with:
# option readfile ~/thefile.opts

button .but1