Rectangle wont appear in the Canvas?

What I’m trying to do:
Draw a simple rectangle on the Canvas. I copy pasted, directly from Anvil docs.

def canvas_1_reset(self, **event_args):
    """This method is called when the canvas is reset and cleared, such as when the window resizes, or the canvas is added to a form."""
    
    c = self.canvas_1
  
    # Set the stroke and fill styles
    c.stroke_style = "#2196F3"
    c.line_width = 3
    c.fill_style = "#E0E0E0"

    # Draw a filled rectangle  
    c.fill_rect(100, 100, 50, 75)
    pass

What I’ve tried and what’s not working:
The rectangle will not appear in my app. What am I doing wrong?

Clone link:
share a copy of your app

The canvas origin is on the top left conrer, X positive goes to the right and Y positive goes down. A rectangle with origin on (100, 100) is drawn below the canvas visible area.

Try changing to c.fill_rect(0, 0, 50, 75).

4 Likes