> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

Gradio events allow you to attach event listeners to components, triggering functions when specific user interactions occur.

## Common Event Methods

Most Gradio components support the following event listeners:

### change

Triggered when the value of the component changes either because of user input OR because of a function update.

```python theme={null}
component.change(fn, inputs, outputs)
```

### input

Triggered when the user changes the value of the component.

```python theme={null}
component.input(fn, inputs, outputs)
```

### click

Triggered when the component is clicked.

```python theme={null}
component.click(fn, inputs, outputs)
```

### submit

Triggered when the user presses enter in a textbox or clicks the submit button.

```python theme={null}
component.submit(fn, inputs, outputs)
```

### select

Triggered when the user selects an item in the component.

```python theme={null}
component.select(fn, inputs, outputs)
```

## Event Parameters

All event methods accept the following parameters:

<ParamField path="fn" type="Callable | None" default="None">
  The function to call when this event is triggered. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
</ParamField>

<ParamField path="inputs" type="Component | Sequence[Component] | None" default="None">
  List of gradio components to use as inputs. If the function takes no inputs, this should be an empty list.
</ParamField>

<ParamField path="outputs" type="Component | Sequence[Component] | None" default="None">
  List of gradio components to use as outputs. If the function returns no outputs, this should be an empty list.
</ParamField>

<ParamField path="api_name" type="str | None" default="None">
  Defines how the endpoint appears in the API docs. Can be a string or None. If set to a string, the endpoint will be exposed in the API docs with the given name.
</ParamField>

<ParamField path="api_description" type="str | None | Literal[False]" default="None">
  Description of the API endpoint. Can be a string, None, or False.
</ParamField>

<ParamField path="scroll_to_output" type="bool" default="False">
  If True, will scroll to output component on completion.
</ParamField>

<ParamField path="show_progress" type="Literal['full', 'minimal', 'hidden']" default="'full'">
  How to show the progress animation while event is running: "full" shows a spinner which covers the output component area as well as a runtime display in the upper right corner, "minimal" only shows the runtime display, "hidden" shows no progress animation at all.
</ParamField>

<ParamField path="queue" type="bool" default="True">
  If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled.
</ParamField>

<ParamField path="batch" type="bool" default="False">
  If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter.
</ParamField>

<ParamField path="max_batch_size" type="int" default="4">
  Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True).
</ParamField>

<ParamField path="preprocess" type="bool" default="True">
  If False, will not run preprocessing of component data before running 'fn'.
</ParamField>

<ParamField path="postprocess" type="bool" default="True">
  If False, will not run postprocessing of component data before returning 'fn' output to the browser.
</ParamField>

<ParamField path="cancels" type="dict | list[dict] | None" default="None">
  A list of other events to cancel when this listener is triggered. For example, setting cancels=\[click\_event] will cancel the click\_event.
</ParamField>

<ParamField path="trigger_mode" type="Literal['once', 'multiple', 'always_last'] | None" default="None">
  If "once" (default for all events except .change()) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always\_last" (default for .change() and .key\_up() events) would allow a second submission after the pending event is complete.
</ParamField>

<ParamField path="js" type="str | Literal[True] | None" default="None">
  Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
</ParamField>

<ParamField path="concurrency_limit" type="int | None | Literal['default']" default="'default'">
  If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency\_limit.
</ParamField>

<ParamField path="concurrency_id" type="str | None" default="None">
  If set, this is the id of the concurrency group. Events with the same concurrency\_id will be limited by the lowest set concurrency\_limit.
</ParamField>

<ParamField path="api_visibility" type="Literal['public', 'private', 'undocumented']" default="'public'">
  Controls the visibility and accessibility of this endpoint. Can be "public" (shown in API docs and callable), "private" (hidden from API docs and not callable), or "undocumented" (hidden from API docs but callable).
</ParamField>

<ParamField path="validator" type="Callable | None" default="None">
  Optional validation function to run before the main function. If provided, this function will be executed first with queue=False, and only if it completes successfully will the main function be called.
</ParamField>

## Dependency Object

Event methods return a Dependency object that can be used to chain events:

### then

Triggered after directly preceding event is completed, regardless of success or failure.

```python theme={null}
dependency.then(fn, inputs, outputs)
```

### success

Triggered after directly preceding event is completed, if it was successful.

```python theme={null}
dependency.success(fn, inputs, outputs)
```

### failure

Triggered after directly preceding event is completed, if it failed.

```python theme={null}
dependency.failure(fn, inputs, outputs)
```

## Example

```python theme={null}
import gradio as gr

with gr.Blocks() as demo:
    first_textbox = gr.Textbox()
    second_textbox = gr.Textbox()
    button = gr.Button("Submit")
    
    dependency = button.click(
        lambda x: "Hello, " + x,
        first_textbox,
        second_textbox
    )
    dependency.success(
        lambda: gr.Info("Greeting successful"),
        None,
        None
    )
    dependency.failure(
        lambda: gr.Warning("Greeting failed"),
        None,
        None
    )

demo.launch()
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.