On 18.12.20 13:50, Pratyush Yadav wrote: > On 17/12/20 11:14PM, Stefan Haller wrote: >> On 17.12.20 22:49, Pratyush Yadav wrote: >>> Hi, >>> >>> On 24/11/20 10:23PM, Stefan Haller wrote>>>> +proc convert_rgb_to_gray {rgb} { >>>> + # Simply take the average of red, green and blue. This wouldn't be good >>>> + # enough for, say, converting a photo to grayscale, but for this simple >>>> + # purpose of approximating the brightness of a color it's good enough. >>>> + lassign [winfo rgb . $rgb] r g b >>> >>> Is there no simpler way to extract r, g, and b? This is a little cryptic >>> to be honest. >> >> Actually, I find this pretty elegant, and from what I have seen, it's >> idiomatic Tcl. A less cryptic way would be (untested): >> >> set components [winfo rgb . $rgb] >> set r [lindex $components 0] >> set g [lindex $components 1] >> set b [lindex $components 2] >> >> But I much prefer the one-line version. > > I agree. Using lassign is much neater. But that is not my point. I am > talking about the "[winfo rgb . $rgb]". This call generates the list > that is then assigned to the 3 variables. This part is a little cryptic. > Is there no simpler way to separate out the r, g, and b values? According to the winfo man page this is the only way to do this; see [1]. Instead of the lassign, you can also do foreach {r g b} [winfo rgb . $rgb] {} but I don't think that's better. -Stefan [1] https://www.tcl.tk/man/tcl8.6/TkCmd/winfo.htm