How to assign icons to `gnotebook()` tabs?

余生颓废 提交于 2020-01-07 05:27:12

问题


I am using gWidgets2 to create a tabbed GUI, and I would like each tab to have an associated icon (image).

Consider:

require(gWidgets2)
w <- gwindow("notebook example", visible=T)
nb <- gnotebook(container=w)
gbutton("Refresh", label="Refresh", container=nb) ## note label argument
gbutton("Info", label="Info", container=nb)

How can I assign the refresh icon next to the label of the 1st tab? And the info icon to the 2nd tab?


回答1:


Something like this can be modified to suit your needs:

function add_stock_icon(nb, nm, page) {
    child <- nb$widget$getNthPage(page-1)
    box <- nb$widget$getTabLabel(child)
    icon <- gimage(stock.id=nm)
    box$packStart(icon$Widget)
}



回答2:


As per the accepted answer, the following does exactly what needed:

add_stock_icon <- function(nb, nm, page, left=TRUE){
    child <- nb$widget$getNthPage(page-1)
    box <- nb$widget$getTabLabel(child)
    icon <- gimage(stock.id=nm)
    box$packStart(icon$widget$parent)
    if(left) box$reorderChild(icon$widget$parent, 0)
}

##add icons to the left of tab labels
add_stock_icon(nb, "refresh", 1)
add_stock_icon(nb, "info", 2)



回答3:


With latest GIT of gWidgets2RGtk2 you can simply do:

nb$add_tab_icon(1, "refresh")
nb$add_tab_icon(2, "info")


来源:https://stackoverflow.com/questions/24706434/how-to-assign-icons-to-gnotebook-tabs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!