嗨,
我正在寻找一种方法在我的ttk ::按钮的右角添加一个三角形,如下所示:
首先你需要图像:
set imgred [image create photo -file redcorner.png]
set imggreen [image create photo -file greencorner.png]
Run Code Online (Sandbox Code Playgroud)
接下来为每种颜色创建一个样式元素:
ttk::style element create Red.Corner.TButton.indicator image $imgred
ttk::style element create Green.Corner.TButton.indicator image $imggreen
Run Code Online (Sandbox Code Playgroud)
现在为两个按钮样式中的每一个创建布局.可以使用检索原始ttk ::按钮布局
ttk::style layout TButton
Run Code Online (Sandbox Code Playgroud)
我们使用它作为模板并添加我们的指标元素.
(编辑:请注意,不同的主题可能有不同的布局.
下面的示例是针对'默认'主题.)
ttk::style layout Red.Corner.TButton {
Button.border -sticky nswe -border 1 -children {
Button.focus -sticky nswe -children {
Button.padding -sticky nswe -children {
Button.label -sticky nswe
Red.Corner.TButton.indicator -side right -sticky ne}}}}
ttk::style layout Green.Corner.TButton {
Button.border -sticky nswe -border 1 -children {
Button.focus -sticky nswe -children {
Button.padding -sticky nswe -children {
Button.label -sticky nswe
Green.Corner.TButton.indicator -side right -sticky ne}}}}
Run Code Online (Sandbox Code Playgroud)
现在所有部分都已准备好创建按钮:
ttk::button .b -text hello -style Red.Corner.TButton
Run Code Online (Sandbox Code Playgroud)
要更改指示器颜色,只需使用其他样式重新配置:
.b configure -style Green.Corner.TButton
Run Code Online (Sandbox Code Playgroud)
参考文献:ttk :: style