LED

LED stands for light-emitting diode. Often people use LED to refer to a style of graphical display that resembles this type of electronic component.


David Wijnants writes, "[...] http://www.xs4all.nl/~arjenvm/pics/index.html has lots of icons 'n stuff, including red and green 'bullets'. Just stick a .GIF image on a canvas, or in a label, and switch images when you need to - for example :

      image create photo red -file smb_red.gif
      image create photo green -file smb_green.gif
      pack [ label .led -image red -height 50 -width 50 ]
      pack [ button .red -text Rood -command { .led configure -image red
            } ] -fill x
      pack [ button .green -text Groen -command { .led configure -image green
            } ] -fill x

With Mark G. Saye's led package [L1 ], "you can create leds (labels) with different sizes and colors, and you can flash them (toggle bg/fg colors and normal/active states), disable (and resume) flashing. There's even a demo for Knight Rider fans."

Identifier: led
Version: 0.0.2
Title: A library of led routines.
Creator: Mark G. Saye <[email protected]>
Description: Provides routines for leds. 
Rights: BSD
URL: http://www.binarism.com/tk/ 
Available: 2003-04-20
Architecture: tcl
Type: Software
Subject: led
Language: en

DKF does it this way:

### MAKE AN IMAGE ###

set width 50
set height 20

image create photo led10x5 -width $width -height $height
led10x5 put -to 0                 0                 $width 1       grey40
led10x5 put -to 0                 0                 1      $height grey40
led10x5 put -to [expr $width - 1] 0                 $width $height grey40
led10x5 put -to 0                 [expr $height -1] $width $height grey40
### EASY COLOUR CONFIG ###
array set ledcols {red red1 green green1 off grey25}
### UTILITY PROCS ###
proc makeLED {w {initState off}} {
    global ledcols
    label $w -image led10x5 -bg $ledcols($initState) -bd 0
}
proc setLED {w state} {
    global ledcols
    $w configure -bg $ledcols($state)
}

#demo code

foreach nr {1 2 3 4 5 6 7 8} {
  makeLED .led$nr off
  pack .led$nr -side left -padx 10
}
foreach nr {1 2 3 4 5 6 7 8} {
  setLED .led$nr red
  update
  after 500
}
 
foreach nr {1 2 3 4 5 6 7 8} {
  setLED .led$nr green
  update
  after 500
}

Other code and commentary on the same subject appears in [L2 ].