I'm getting a colorfill error for my Python turtle graphics code, but I don't understand why. The method t.fillcolor()
should accept 3 values as the r,g,b values for the fillcolor of a turtle shape, where t
is a turtle. However, any three values in the method produce an error.
This is how the t.fillcolor()
is explained in my book:
Here is the code:
from turtle import Turtle,Screen
#might want to use:
#from turtle import *
from random import randint
def hexagon(t, length):
"""Draws a hexagon with the given length."""
for count in range(6):
t.forward(length)
t.left(60)
def radialPattern(t, n, length, shape):
"""Draws a radial pattern of n shapes with the given length."""
for count in range(n):
shape(t, length)
t.left(360 / n)
screen = Screen() #create a screen object
screen.setup(width=600,height=400) #size
screen.bgcolor("lightblue")
screen.title("My turtle")
t = Turtle()
#added code here:
t.fillcolor(20,75,153)
t.begin_fill()
radialPattern(t,5,30,hexagon)
t.end_fill()
screen.exitonclick() #keep the screen open until user closes it
The code execution starts at line screen = Screen() #create a screen object
Here is the error:
Traceback (most recent call last):
File "D:\Turtle for final.py", line 25, in <module>
t.fillcolor(20,75,153)
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\turtle.py", line 2289, in fillcolor
color = self._colorstr(args)
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\turtle.py", line 2697, in _colorstr
return self.screen._colorstr(args)
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\turtle.py", line 1167, in _colorstr
raise TurtleGraphicsError("bad color sequence: %s" % str(color))
turtle.TurtleGraphicsError: bad color sequence: (20, 75, 153)
I've gotten this method to work properly plenty of times. It's just not working here and I don't understand why.
If someone could help me out, I would appreciate it.