'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?
Here's the whole program, it worked before, but as soon as I added the whole "FoofTup" thing, it stopped working... Any help here?:
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()```
Solution 1:[1]
You are missing the screen object, it is needed since your FoofTup color is a range of 0 - 255, so you need to set the colormode to 255
Your code should look like this
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()
Anyway, next time you should also include your error message, you can see the error message on your console.
For your case the error was
turtle.TurtleGraphicsError: bad color sequence: (255, 0, 255)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | taipei |
