To help identify what is being received in event_args
, you can:
print(event_args)
For example, you might see:
{'event_name': 'click', 'sender': <anvil.Button object>}
event_args
is a Python dictionary, so this gives you the names and values of every keyword argument passed, documented or not. This works no matter who or what called your event-handler.
1 Like
These are in fact documented! Check out https://anvil.works/doc/#component_events
event_args
always contains:
-
event_name
, for example 'click'
-
sender
, the Python object that triggered the event. For example, a click
event triggered by a Link will have sender
as the Link object.
These built-in event arguments are mostly useful if you’re using one function to handle multiple types of event, or events on multiple components. Of course, other event_args
may be present depending on the event, depending on what the component provides.
No slight intended, @meredydd. I was thinking more about events in general, e.g. for an event provided by a Custom Component. In that case, there may be no up-to-date documentation, or no documentation at all.
Event-handlers can also be invoked directly by Python code. In this case, the caller may be passing additional named arguments, to give the handler a more complete picture of the situation. Conversely, it might be failing to pass the usual parameters! Most likely, neither situation will be documented.
print(event_args)
, used sparingly, can be very revealing in all of these cases. I’m very glad you guys made it possible.
1 Like