考虑以下输入框:
w <- gwindow()
g <- ggroup(cont=w, horizontal=F)
ed <- gedit(cont=g)
cbb <- gcombobox(letters, editable=T, use_completion=T, cont=g)
如果包含字符串gedit()
,我如何制作红色的gcombobox()
/ asdf
输入框和白色的前景(文本本身)的背景?
答案 0 :(得分:0)
正如评论中所建议的那样,以下工作可以完成,您可以将red
替换为#FF6666
(浅红色褪色)或任何颜色:
addHandlerKeystroke(ed, function(h,...){
if(svalue(ed)=="asdf"){
ed$widget$modifyBase(GtkStateType["normal"], "red")
ed$widget$modifyText(GtkStateType["normal"], "white")
} else {
ed$widget$modifyBase(GtkStateType["normal"], NULL)
ed$widget$modifyText(GtkStateType["normal"], NULL)
}
})
对于gcombobox()
,它略有不同:
addHandlerChanged(cbb, function(h,...){
if(svalue(cbb)=="asdf"){
cbb$widget$getChildren()[[1]]$modifyBase(GtkStateType["normal"], "red")
cbb$widget$getChildren()[[1]]$modifyText(GtkStateType["normal"], "white")
} else {
cbb$widget$getChildren()[[1]]$modifyBase(GtkStateType["normal"], NULL)
#cbb$widget$getChildren()[[1]]$modifyText(GtkStateType["normal"], NULL)
}
})