Search code examples
pythonpython-turtle

How do I select a new random color in Python turtle?


So I'm recreating the DVD logo in turtle. I have these variables

r = random.randint(0,255)
g = random.randint(0,255)
b = random.randint(0,255)

And they work for selecting a random color once, but only once. How I get it to select another random color? Also, I'm new I know I suck


Solution

  • You would have to call the code a second time.

    For ex.

    def get_random_color():
    
       r = random.randint(0,255)
       g = random.randint(0,255)
       b = random.randint(0,255)
    
       return (r,g,b)
    
    color = get_random_color()
    

    Whenever you call the function above you will get a new rgb value in a tuple.