Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggle color

Status
Not open for further replies.

kokoko12000

Programmer
Apr 14, 2003
13
US
Hi all,
I have many shapes, (say circles) in my window. Say each shape's color is black. Now using my Mouse I want to toggle colors on each shape, when i click on them. Pls give some suggestions how to do this?

-j
 
Exec, clic and see.
Code:
  pack [canvas .c -height 200 -width 200]
  for {set i 0} {$i < 10} {incr i}   {
    for {set j 0} {$j < 10} {incr j}     {
      set x1 [expr {$j * 20}]
      set y1 [expr {$i * 20}]
      set x2 [expr {$x1 + 20}]
      set y2 [expr {$y1 + 20}]
      .c create rectangle $x1 $y1 $x2 $y2 -fill black -outline white -tags rect$i-$j
      .c bind rect$i-$j <ButtonPress-1> [list toggle rect$i-$j]
    }
  }
  proc toggle {tag}   { 
    set color [.c itemcget $tag -fill ]
    set color [expr {$color == &quot;black&quot; ? &quot;gray&quot; : &quot;black&quot;}]
    .c itemconfig $tag -fill $color 
  }
HTH

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top