[ulis], 2003-09-17 (Thanks to *NOT* change my formatting style) [KPV]: Heaven help you if you ever add comments to your code. [ulis] done ---- [http://perso.wanadoo.fr/maurice.ulis/tcl/flowers.gif] ---- Please, download the images files in the current directory before executing the script. http://perso.wanadoo.fr/maurice.ulis/tcl/flower-1.gif http://perso.wanadoo.fr/maurice.ulis/tcl/flower-2.gif http://perso.wanadoo.fr/maurice.ulis/tcl/flower-3.gif ---- # ------------- # nmage/bimage packages # ------------- # create a canvas with n images proc nmage {w args} \ { # take size from the first image set image [lindex $args 0] set ww [image width $image] set hh [image height $image] # center coordinates set x [expr {$ww / 2}] set y [expr {$hh / 2}] # create canvas canvas $w -width $ww -height $hh -highlightt 0 # create the images set n 0 foreach image $args \ { $w create image $x $y -anchor center \ -image $image -tags _[incr n] } } # create a canvas with a mini and a micro image # args: widget id, full image name, mini image name, micro image name, background color proc bimage {num flower image1 image2 {color ""}} \ { # take size from the first image set ww [image width $flower] set hh [image height $flower] # create the mini & the micro image from the full image foreach {type factor} {mini 4 micro 8} \ { set ww2 [expr {$ww / $factor}] set hh2 [expr {$hh / $factor}] image create photo ${type}$num -width $ww2 -height $hh2 ${type}$num copy flower$num -subsample $factor } # create a canvas with the mini & micro images nmage .$num $image1 $image2 # register associated info set ::info(.$num) [list $flower $color] } # ------------- # mechanism # ------------- # called on n-th choice (click on canvas) proc change {n} \ { # get corresponding info foreach {name color} $::info(.$n) break # show the n-th image select .0 $n 3 # show its name .name config -text $name # set background color foreach w {. .name .0 .1 .2 .3} { $w config -bg $color } # size the little images foreach w {.1 .2 .3} { select $w [expr {$w == ".$n" ? 1 : 2}] } } # show the n-th image proc select {w n {max 2}} \ { for {set i 1} {$i <= $max} {incr i} \ { if {$i == $n} { $w itemconf _$i -state normal } \ else { $w itemconf _$i -state hidden } } } # ------------- # create images # ------------- foreach image {flower1 flower2 flower3} \ file {flower-1.gif flower-2.gif flower-3.gif} \ { image create photo $image -file $file } # ------------- # create widgets # ------------- # the canvas with the ful images nmage .0 flower1 flower2 flower3 # the label with the name label .name -font {Times -24} # the selection canvas foreach {i color} {1 DeepPink3 2 orange 3 blue} \ { # canvas with a mini and a micro image bimage $i flower$i mini$i micro$i $color # call change on click bind .$i <1> [list change $i] } # ------------- # place & display widgets # ------------- grid .0 -row 0 -column 1 -columnspan 3 grid .name -row 1 -column 1 -columnspan 3 foreach i {1 2 3} { grid .$i -row 2 -column $i } # ------------- # do it! # ------------- wm title . flowers change 1 ---- [Category Example] | [Category Graphics]