Python: screen colors adjuster using Turtles I am a total beginner in Python and I am trying with the modules Turtle. I am currently trying to code for 3 sliders (R, G, B) for adjusting the colors of the turtle screen. However, I found parts of my codes filled with redundancies, could anyone please tell me how to trim the code to make it more compact and clear, especially in the draw_red, draw_green, draw_blue parts? Thanks in advance.
import turtle

turtle.setworldcoordinates(0, 0, 4, 255)
turtle.colormode(255)
turtle.tracer(False)

colors = ['red', 'green', 'blue']
painters = []
red_x, green_x, blue_x = 1, 2, 3
turtle.bgcolor(0,0,0)
def spawningPainters():
    global painter
    for i in range(len(colors)):
        painter = turtle.Turtle()
        painters.append(painter)
        painter.up()
        painter.speed(0)
        painter.setheading(90)
        painter.color(colors[i])
        painter.pencolor('black')
        painter.shape('turtle')
        painter.shapesize(5, 5, 5)
        xPos = i + 1
        painter.goto(xPos, 0)

def assign_painters():
    global redPainter, greenPainter, bluePainter
    redPainter = painters[0]
    greenPainter = painters[1]
    bluePainter = painters[2]

def draw_red(x, y):
    redPainter.ondrag(None)
    x = red_x
    redPainter.goto(x, y)
    redPainter.ondrag(draw_red)
    update_screen_color()

def draw_green(x, y):
    greenPainter.ondrag(None)
    x = green_x
    greenPainter.goto(x, y)
    greenPainter.ondrag(draw_green)
    update_screen_color()

def draw_blue(x, y):
    bluePainter.ondrag(None)
    x = blue_x
    bluePainter.goto(x, y)
    bluePainter.ondrag(draw_blue)
    update_screen_color()

def update_screen_color():
    red = max(min(redPainter.ycor(), 255) , 0)
    green = max(min(greenPainter.ycor(), 255), 0)
    blue = max(min(bluePainter.ycor(), 255), 0)

    turtle.bgcolor(int(red), int(green), int(blue))

def back_to_origin():
    for painterIndex in range(len(painters)):
        painters[painterIndex].goto(painterIndex + 1, 0)

def listening_input():
    redPainter.ondrag(draw_red)
    greenPainter.ondrag(draw_green)
    bluePainter.ondrag(draw_blue)
    turtle.onkeypress(back_to_origin, 'c')

def main():
    spawningPainters()
    assign_painters()
    listening_input()

main()
turtle.listen()
turtle.tracer(True)
turtle.mainloop()
Review
I wasn't able to figure out a way to make the code more compact and in my opinion the code is pretty clear. However I do have some other feedback.
Use a proper main
Instead of:
turtle.setworldcoordinates(0, 0, 4, 255)
turtle.colormode(255)
turtle.tracer(False)
turtle.bgcolor(0,0,0)

...

def main():
    spawningPainters()
    assign_painters()
    listening_input()

main()
turtle.listen()
turtle.tracer(True)
turtle.mainloop()

Do:
...

if __name__ == &quot;__main__&quot;:
    turtle.setworldcoordinates(0, 0, 4, 255)
    turtle.colormode(255)
    turtle.tracer(False)
    turtle.bgcolor(0,0,0)

    spawningPainters()
    assign_painters()
    listening_input()

    turtle.listen()
    turtle.tracer(True)
    turtle.mainloop()

For more information you can look at this post: https://stackoverflow.com/questions/419163/what-does-if-name-main-do
Prevent the turtle from going outside of the window
With the current code it is possible to drag the turtle outside of the window. If you then stop dragging you cannot get it back unless you reset the position. To prevent this from happening we can limit the boundaries of y inside of the draw functions.
def draw_blue(x, y):
    bluePainter.ondrag(None)
    x = blue_x
    y = min(y, 255)
    y = max(y, 0)
    bluePainter.goto(x, y)
    bluePainter.ondrag(draw_blue)
    update_screen_color()

By doing this the min and max calls can be removed from the update_screen_color function. However you may want to leave them as a form of defensive programming in case you add more features.
def update_screen_color():
    red = redPainter.ycor()
    green = greenPainter.ycor()
    blue = bluePainter.ycor()

    turtle.bgcolor(int(red), int(green), int(blue))

Update screen color when going back to the origin
When the position is put back to the origin the screen color is not redrawn. Unless this is intended it would be good to call the update_screen_color function at the end of the back_to_origin function.
Few tips
The global painter variable is not used anywhere outside of the spawningPainters function, so it can be removed.
Move the colors list to the spawningPainters function as it is not used anywhere else.
You might want to rename spawningPainters to spawn_painters.
Extra
Add typing to the painters list
When an empty list is declared the intellisense of your IDE may have trouble figuring out what type of elements the list will contain. By adding type annotations you can help the intellisense better understand your code.
Instead of:
painters = []

Do:
from typing import List

...

painters: List[turtle.Turtle] = []