Version 7 of image

Updated 2002-12-09 13:48:14

http://www.purl.org/tcl/home/man/tcl8.4/TkCmd/image.htm

Someone want to mention the Img extension and why it is so useful?


See also Buttons with image and text - Images With Transparency and Plain Images - Reading GIF image dimensions - Reading JPEG image dimensions - Reading PNG image dimensions - Tk image Dos and Don'ts -


I (FW) wrote this code in a couple minutes the other day to occupy myself, which generates a 500x500 image of randomly-colored pixels and displays it in a window. I think this summarizes Tcl's image generation capabilities well (and the images it makes are pretty mesmerising, too). Might as well put it up here:

 proc generate_data {} {
   set data [list]
   for {set x 0} {$x < 500} {incr x} {
     set row [list]
     for {set y 0} {$y < 500} {incr y} {
       lappend row [format "#%02x%02x%02x" [random_byte] [random_byte] [random_byte]]
     }
     lappend data $row
   }
   return $data
 }

 proc random_byte {} {
   return [expr {int(rand() * 256)}]
 }

 set image [image create photo] 
 $image put [generate_data]

 label .l -image $image
 pack .l

RS: Cool! In my copy I just added the line

 bind . <Return> {$image put [generate_data]}

to let the CPU work more ;-)


Tk syntax help - Arts and crafts of Tcl-Tk programming - Category Command - Category Graphics