[issue33289] tkinter askcolor returning floats for r, g, b values instead of ints

Terry J. Reedy report at bugs.python.org
Thu Jan 21 04:19:16 EST 2021


Terry J. Reedy <tjreedy at udel.edu> added the comment:

https://www.tcl.tk/man/tcl8.6/TkCmd/winfo.htm says
"winfo rgb window color
    Returns a list containing three decimal values in the range 0 to 65535, 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."

Since tk represents data as strings, 'decimal value in [0, 65535)' means 'integer value represented by decimal digits'.  'correspond to color in the window' implies that the mapping from color to decimal value could depend on the window.  The mapping *does* differ between systems (see below).

https://www.tcl.tk/man/tcl8.6/TkLib/GetColor.htm
Lists possible return values, hence acceptible forms, as name or '#' followed by 1 to 4 hex digits.  It continues with "Each R, G, or B represents a single hexadecimal digit. The four forms permit colors to be specified with 4-bit, 8-bit, 12-bit or 16-bit values. When fewer than 16 bits are provided for each color, they represent the most significant bits of the color, while the lower unfilled bits will be repeatedly replicated from the available higher bits. For example, #3a7 is the same as #3333aaaa7777."

This omits to say what happens when there are 2 or 3 hex digits.  Windows ignores 3rd and 4th hex digits.  On Windows, dividing by 257 instead of 256 would be correct.  However, 256 works because the 'error', represented by the remainder, is always in [0, 256).  MacOS does not ignore digits.

https://www.tcl.tk/man/tcl8.6/TkCmd/colors.htm
Lists current color names and their values as 16 bit decimals.

The PR is blocked because the new colorchooser tests pass on Windows and macOS but fail on Ubuntu.  Cheryl speculated that the color names values vary across systems.  I think that it might instead be a coding issue, but I want to understand coding on Windows and Mac better before looking into Linux.

----------
versions: +Python 3.10 -Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33289>
_______________________________________


More information about the Python-bugs-list mailing list