From Newsgroup: comp.lang.tcl
On 07/08/2025 22:05, saito wrote:
This is what I use:
lassign [winfo rgb . $c] r g b
set r [expr {$r % 256}]
set g [expr {$g % 256}]
set b [expr {$b % 256}]
format "\#%02x%02x%02x" $r $g $b
Interesting choice to use the least significant byte of the color
values. It happens to work as long as both bytes are the same, which
they seem to be for now. But I would have picked the most significant
byte myself, just in case there may be graphics cards in the future with
more than 8 bits per color.
Within Tk it's also perfectly valid to specify an rgb value with 4 hex
chars per color. So for that use case you could just simplify to:
format #%04x%04x%04x {*}[winfo rgb . $c]
Schelte.
--- Synchronet 3.21a-Linux NewsLink 1.2