Fit image size to a small button
I am using R and tcl/tk package to make R GUI application. Now I got a problem and could not figure it out. Looking for hlep...
I want to put an arrow image on a button. However the size of the image is too big and I want to have a small button. How can I resize the image and fit the the button size?
tt <- tktoplevel()
image1 <- tclVar()
tcl("image开发者_如何转开发","create","photo",image1,file="toRight.gif")
imgAsButton <- tkbutton(tt,image=image1,bg="white")
tkpack(imgAsButton)
Thanks
Using a graphic converter would be the best choice, but if you can't do that, here is a solution using a gif file
iconFile <- "http://barre.nom.fr/vtk/images/logo-tcl-tk.gif"
tmp <- tempfile()
download.file(iconFile, tmp)
iconName <- "::tcl::logo"
largerIconName <- "::tcl::larger_logo"
i1 <- tkimage.create("photo", iconName, file = tmp)
i2 <- tkimage.create("photo", largerIconName)
## enlarge by factor of 2
tcl(i2, "copy", i1, zoom=2)
## shrink by factor of 2
## tcl(i2, "copy", i1, subsample=2)
w <- tktoplevel()
l_full <- ttklabel(w, image=iconName) ## or ttkbutton if you want
l_twice <- ttklabel(w, image=largerIconName)
sapply(list(l_full, l_twice), tkpack)
精彩评论