Version 4 of winfo rgb

Updated 2004-03-30 20:45:37

A subcommand of Tk's winfo command.

winfo rgb window color

Returns a list containing three decimal values, which are the red, green, and blue intensities that correspond to color in the window given by window. Color may be specified in any of the forms acceptable for a color option.

According to Jeff Hobbs, the decimal values are always 16 bits [L1 ].


Here's a quick way to parse the return string into three separate variables:

    foreach {r g b} [winfo rgb . $some_color] break

...or if you don't like the "break":

    foreach {red green blue} [winfo rgb . red] {}

The technique may seem obscure at first, but apparently it's an accepted idiom in TCL [L2 ].


Note that "winfo rgb" is not idempotent (or surjective) over the space of decimal triples. CL believes that the point is that the range space of "winfo rgb" is the display's color palette (is that the right GUI vernacular?), and is thus smaller than the full cartesian product ([0-65535],[0-65535],[0-65535]) one might otherwise expect.

This presented with VNC service for which

    winfo rgb . #ffff1fffffff

is

    65535 0 65535

rather than the

    65535 7967 65535

delivered by a better-endowed display.

A start to a work-around for this is ...


Category Command | Tk syntax help | Arts and Crafts of Tcl-Tk Programming