[R-gui] Re: tcltk: "Image" rather than bitmap loaded on tklabel

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Jul 17 10:34:00 MEST 2003


James Wettenhall <wettenhall at wehi.edu.au> writes:

> Dirk,
> 
> Did you figure out how to display images in Tk widgets?
> 
> I finally got it working as follows:
> 
> library(tcltk)
> tt <- tktoplevel()
> tclRequire("Img")
  ^^^^^^^^^^^^^^^^^

Ah, that was what you needed to get PNG. However, note that the Img
extension isn't installed by default, and is not included with e.g.
RedHat. Without it, you only get GIF and PNM support (but of course
nearly everything can be converted to PNM).

> tkcmd("image","create","photo","foo",file="foo.png")
> imgAsLabel <- tklabel(tt,image="foo",bg="white")
> tkpack(imgAsLabel)

1.8.0 should have a tkimage.create function that actually works, i.e.

  tkimage.create("photo", img, file="foo.pnm")

should work. 

Already in the current version, you can use a tclVar object instead of
an explicit image name. This avoids trouble if two functions use the
same name, or accidentally overwriting an existing Tcl command (e.g.
calling the image "image" is a bad idea.) The finalizer code is
probably underdeveloped, though: An image should be deleted with
"image delete foo", not "unset foo", so it is not getting cleared
automatically when an image variable goes out of scope. 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-SIG-GUI mailing list