Tcl/Tk 8.5 中单选按钮的颜色 [英] Color of Radiobutton in Tcl/Tk 8.5

查看:44
本文介绍了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/circle)? 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?

欢迎提出任何建议.

亲切的问候,修复

推荐答案

radiobutton 命令有 -selectcolor 选项.只需为此选项指定颜色即可.

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

如果您不想为每个单选按钮单独指定颜色,您可以在 xresources 数据库中设置此颜色.

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

<小时>

编辑:ttk 的解决方案:


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

如果您不想重新定义全局样式,您可以为单选按钮定义自己的 ttk::style,并将其用于特定的小部件:

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"
...

这篇关于Tcl/Tk 8.5 中单选按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆