October 22, 2024
Chicago 12, Melborne City, USA
python

How can i fix the error – “Bad Colour Sequence” from line 31?


I am making a Python Turtle project that will let me input 3 colour values which then get used as a colour for a circle, then it should print the rgb values of the colour and the hex values in the text output.
This is the code:

import turtle 
from turtle import colormode
import random
import time
turtle.speed(0)

def randomchoi():
    turtle.colormode(255)
    randr = random.randint(0, 255)
    randg = random.randint(0, 255)
    randb = random.randint(0, 255)
    rand = (randr, randg, randb)
    turtle.color(rand)
    turtle.begin_fill()
    turtle.left(180)
    turtle.forward(55)
    turtle.left(135)
    turtle.clear()
    turtle.circle(100)
    turtle.end_fill()
    print(rand)
    hexrand = '#%02x%02x%02x' % (rand)
    print(hexrand)

def rgbselect():
    turtle.colormode(255)
    rgbr = input("Red = ")
    rgbg = input("Green = ")
    rgbb = input("Blue = ")
    rgb = (rgbr, rgbg, rgbb)
    turtle.color(rgb)
    turtle.begin_fill()
    turtle.left(180)
    turtle.forward(55)
    turtle.left(135)
    turtle.clear()
    turtle.circle(100)
    turtle.end_fill()
    print(rgb)
    hexrgb = '#%02x%02x%02x' % (rgb)
    print(hexrgb)
    

rgbselect()

Ignore randchoi because its working as i wanted, but the focus of my problem is "rgbselect".
The code works until its time for the turtle colour to be changed to the tuple rgb
What can i do?

I have tried to importing colormode from turtle directly, it made no difference though.

I have also tried changing the rgbr, rgbg, and rgbb to integers using:

import turtle 
from turtle import colormode
import random
import time
turtle.speed(0)

def randomchoi():
    turtle.colormode(255)
    randr = random.randint(0, 255)
    randg = random.randint(0, 255)
    randb = random.randint(0, 255)
    rand = (randr, randg, randb)
    turtle.color(rand)
    turtle.begin_fill()
    turtle.left(180)
    turtle.forward(55)
    turtle.left(135)
    turtle.clear()
    turtle.circle(100)
    turtle.end_fill()
    print(rand)
    hexrand = '#%02x%02x%02x' % (rand)
    print(hexrand)

def rgbselect():
    turtle.colormode(255)
    rgbr = input("Red = ")
    rgbg = input("Green = ")
    rgbb = input("Blue = ")
    **int(rgbr)
    int(rgbg)
    int(rgbb)**
    rgb = (rgbr, rgbg, rgbb)
    turtle.color(rgb)
    turtle.begin_fill()
    turtle.left(180)
    turtle.forward(55)
    turtle.left(135)
    turtle.clear()
    turtle.circle(100)
    turtle.end_fill()
    print(rgb)
    hexrgb = '#%02x%02x%02x' % (rgb)
    print(hexrgb)
    

rgbselect()

It didn’t change the outcome, i also tried to do int(rgb) but that came up with a different error



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video