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
The second version is likely correct, but you need to change each int(rgbr)
, int(rgbg)
, int(rgbb)
with:
rgbr = int(rgbr)
rgbg = int(rgbg)
rgbb = int(rgbb)
Without any further information about the error, I cannot help further.
PS: I posted this answer before reading Barmar's comment, which is equivalent (i.e. doing rgbr = int(input("Red -> "))
and so on for each color component).