Python Forum

Full Version: colorsys.hsv_to_rgb
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
pt = Point(x,y) 
h=angle
s=length
RGB=colorsys.hsv_to_rgb(h, s, 0.0)
pt.setFill(color_rgb(RGB))
pt.draw(win)
I get error message="color_rgb() missing 2 required positional arguments: 'g' and 'b'"

Why? What I'm doing wrong?
I don't know the library you use, but it seems that colorsys.hsv_to_rgb(h, s, 0.0) returns a tuple with 3 elements, and color_rgb(RGB) expects 3 separate arguments. Try with:
R, G, B = colorsys.hsv_to_rgb(h, s, 0.0)
pt.setFill(color_rgb(R, G, B))
Now I get error message:

File "D:\Python\graphics.py", line 962, in color_rgb
return "#%02x%02x%02x" % (r,g,b)
TypeError: %x format: an integer is required, not float
You may try casting the r, g and b values to integer values.
Better yet, try to search for documentation or examples for the module you are using.