Your colormode is probably set to 1.0, so either the individual color coordinates need to be floats in the range 0 to 1, or you need to set the colormode to 255.
you will get this error in case you are generating a random color using a function and you are using the random module and then returning a tuple of 3 random integers, and pass this tuple color function you can fix this issue by writing this turtle.colormode(255)
use this code
import random
import turtle
from turtle import Turtle
turtle.colormode(255)
tim = Turtle()
tim.speed("fastest")
direction = [90, 270]
#colours = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"]
tim.pensize(5)
def random_color():
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
random_color = (r, g, b)
return random_color
while True:
move = random.choice(direction)
tim.forward(40)
tim.color(random_color())
tim.left(move)
screen.colormode(255)and it should work.From the docs:
Your colormode is probably set to 1.0, so either the individual color coordinates need to be floats in the range 0 to 1, or you need to set the colormode to 255.
回答2
you will get this error in case you are generating a random color using a function and you are using the random module and then returning a tuple of 3 random integers, and pass this tuple color function you can fix this issue by writing this turtle.colormode(255)
use this code