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 your ‘Submit’ Button, and scroll to the bottom of the Properties Panel. You’ll see a list of events for the Button.

Click the blue arrows next to ‘click’.

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

You will be taken to the Form Editor’s ‘Code’ view.

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 ‘Add an article’ 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")