What I’m trying to do:
Fill a rectangle on a Canvas with a linear_gradient
What I’ve tried and what’s not working:
See code below. Am I missing an import?
Code Sample:
c=self.canvas_1
my_gradient = c.create_linear_gradient( 0,0,300,0)
print (my_gradient) # <anvil.Canvas.Gradient object>
# now I want to do the following, but get this "AttributeError: 'Canvas.Gradient' object has no attribute 'addColorStop'"
my_gradient.addColorStop(0, "black");
my_gradient.addColorStop(1, "white");
Clone link:
share a copy of your app
If you look here, you can see what methods, properties and events a Canvas object supports.
Thanks. I don’t see a solution to the problem here though.
It should be there. Use snake case instead. ie add_color_stop
. Check the method exists by printing dir(my_gradient)
Paste this in Theme CSS and add this to your role
.anvil-role-gradient {
background-image: linear-gradient(black, white);
}
Replace the colors above with any color. You can add multiple as well.
yes, add_color_stop can be found through a dir(). Thank you. I am on the way now…
<anvil.Canvas.Gradient object> is not found in the documentation, nor is add_color_stop.
thanks for this alternative.