我尝试在 turtle 中使用 rgb 元组作为 pencolor,但是当我尝试 运行 时程序打不开。有什么帮助吗?

I tried to use an rgb tuple for pencolor in turtle, but the program won't open when I try to run it. Any help for that?

这是整个程序,它以前可以运行,但是一旦我添加了整个“FoofTup”东西,它就停止运行了...这里有什么帮助吗?:

import turtle
x = 1
FoofTup = (255, 0, 255)
shape = turtle.Turtle()
shape.hideturtle()
shape.speed(10)
shape.pencolor(FoofTup)
while x < 1000:
    shape.forward(x * 5)
    shape.left(226)
    x += 1
turtle.done()```

您缺少屏幕对象,它是必需的,因为您的 FoofTup 颜色范围是 0 - 255,因此您需要将颜色模式设置为 255

您的代码应如下所示

import turtle

x = 1
FoofTup = (255, 0, 255)
shape = turtle.Turtle()

# Initiate the screen
screen = turtle.Screen()

# Set the colormode to 255
screen.colormode(255)

shape.hideturtle()
shape.speed(10)
shape.pencolor(FoofTup)
while x < 1000:
    shape.forward(x * 5)
    shape.left(226)
    x += 1
turtle.done()

无论如何,下次你也应该包括你的错误信息,你可以在你的控制台上看到错误信息。

对于你的情况,错误是

turtle.TurtleGraphicsError: bad color sequence: (255, 0, 255)