3

For this function I can use tuple elements as arguments:

light_blue = .6, .8, .9
gradient.add_color_rgb(0, *light_blue)

What if i have to add another argument after the tuple?

light_blue = .6, .8, .9
alpha = .5
gradient.add_color_rgba(0, *light_blue, alpha)

does not work. What does work is

gradient.add_color_rgba(0, *list(light_blue)+[alpha])

which does not really look better than

gradient.add_color_rgba(0, light_blue[0], light_blue[1], light_blue[2], alpha)

Is there a better way to do this?

2 Answers 2

6

You could call it like gradient.add_color_rgba(0, *light_blue, alpha=alpha) if you know parameter name for the alpha.

Sign up to request clarification or add additional context in comments.

Comments

2

You can simplify the expression slightly by making a tuple instead of a list containing light_blue and alpha e.g.

gradient.add_color_rgba(0, *(light_blue + (alpha,)))

2 Comments

Depending on light_blue type is quite nasty. IMO it's better to assume that it's any iterable.
Ok now i remember this is the way to create a one-element tuple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.