开发者

Color of Radiobutton in Tcl/Tk 8.5

is it possible to modify the color of a radiobutton's dot (i.e. only the fill-color of the diamond/cir开发者_JAVA技巧cle)? I am already using the classic theme, in order to get the old diamonds. But unfortunately, the fill-color of those diamonds is always some red and I need bright green.

Is that possible? Maybe by creating an own widget that "inherits/extends" the basic radio button?

Any kind of advice is welcome.

Kind regards, mefiX


The radiobutton command has -selectcolor option. Just specify the color for this option.

set a 1
radiobutton .b1 -selectcolor green -variable a -value 1 -text "Option 1"
radiobutton .b2 -selectcolor green -variable a -value 2 -text "Option 2"
radiobutton .b3 -selectcolor green -variable a -value 3 -text "Option 3"
pack .b1 .b2 .b3

If you do not want to specify the color for each radiobutton individually, you can set this colot in xresources database.

option add *Radiobutton.selectColor green
set a 1
radiobutton .b1 -variable a -value 1 -text "Option 1"
radiobutton .b2 -variable a -value 2 -text "Option 2"
radiobutton .b3 -variable a -value 3 -text "Option 3"
pack .b1 .b2 .b3

EDIT: Solution for ttk:

ttk::style theme use classic
ttk::style map TRadiobutton -indicatorcolor {pressed #d9d9d9 selected green}
set a 1
ttk::radiobutton .b1 -variable a -value 1 -text "Option 1"
ttk::radiobutton .b2 -variable a -value 2 -text "Option 2"
ttk::radiobutton .b3 -variable a -value 3 -text "Option 3"
pack .b1 .b2 .b3

You can define your own ttk::style for radiobutton and use it for particular widgets if you do not want to redefine the global style:

ttk::style layout TRadiobuttonGreen [ttk::style layout TRadiobutton]
ttk::style configure TRadiobuttonGreen {*}[ttk::style configure TRadiobutton]
ttk::style map TRadiobuttonGreen {*}[ttk::style map TRadiobutton] -indicatorcolor {pressed #d9d9d9 selected green}

ttk::radiobutton .b1 -style TRadiobuttonGreen -variable a -value 1 -text "Option 1"
...

Color of Radiobutton in Tcl/Tk 8.5

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜