Setting the fill of a rectangle drawn with canvas to an RGB value

7.4k Views Asked by At
w.create_rectangle(x, y, s, s, fill=(109,170,44))

I want to achieve something like this, but when I try it I get an error. I'm creating several rectangles using an array / list and I want them to be this shade of green, but can't seem to find a way that works. So far the only thing that has worked is

w.create_rectangle(x, y, s, s, fill="green")

But it's not the shade I want. Any help is greatly appreciated, and I feel although I'm missing something big and really easy here, but I've been hung up on this problem for awhile now.

1

There are 1 best solutions below

0
On BEST ANSWER

You are getting an "unknown color name" error. You have to either use the name from the list of colors or use hexadecimal format: #RRGGBB

To convert a tuple of integer values to RGB format use this:

colorval = "#%02x%02x%02x" % (109, 170, 44)

This will result in #6daa2c