Tkinter askcolor returning wrong RGB values? Tkinter askcolor returning wrong RGB values? tkinter tkinter

Tkinter askcolor returning wrong RGB values?


This appears to be a bug in tkinter1. askcolor should be returning integers. The fix seems simple: convert the values to integers before converting them to a string:

color_result_rgb = ' '.join(str(int(x)) for x in rgb_tuple) 

1 Looking at the tkinter code, it is indeed intentionally returning a floating point number even though the underlying tcl/tk interpreter is returning an int. This seems like a side effect of the change to the behavior of the / operator in python 3.x

This is what the tkinter code is doing to the raw value:

r, g, b = widget.winfo_rgb(result)return (r/256, g/256, b/256), str(result)

I've submitted a bug report: askcolor is returning floats for r,g,b values instead of ints


I wanted to get the color from the color picker dialog to pass to the create_line method. The askcolor function/method returns ((255.99609375, 0.0, 0.0), '#ff0000'). It's the latter value I need, so these two lines did the trick for me...

rgb, color = askcolor()canvas.create_line((lastx, lasty, event.x, event.y), fill=color)