Anvil components can raise events. For example, when a Button is clicked, it raises the ‘click’ event.

Click on ‘Form1’ in the App Browser to go back to your UI.

Click on the ‘Submit’ Button, and click on click event -> in the Object Palette.

Configuring a click event handler for a Button using the Properties Panel

You will be taken to the Form Editor’s ‘Split’ view, where you’ll see the Code Editor. This is where you write your client-side Python code that runs in the browser.

You’ll see a submit_button_click method on your Form that looks like this:

  def submit_button_click(self, **event_args):
    """This method is called when the button is clicked"""
    pass

This is the Python method that runs when the ‘Submit’ Button is clicked.

For example, to display a simple popup with the text ‘You clicked the button’, edit your submit_button_click function as follows:

  def submit_button_click(self, **event_args):
    # Display a popup that says 'You clicked the button'
    alert("You clicked the button")