Introducing Gradio 5.0

Read More
  1. Helpers
  2. EventData

New to Gradio? Start here: Getting Started

See the Release History

To install Gradio from main, run the following command:

pip install https://gradio-builds.s3.amazonaws.com/9285dd9eb842ee05bd8a0fd4f0f9143788096bbc/gradio-5.9.1-py3-none-any.whl

*Note: Setting share=True in launch() will not work.

EventData

gradio.EventData(ยทยทยท)

Description

When gr.EventData or one of its subclasses is added as a type hint to an argument of a prediction function, a gr.EventData object will automatically be passed as the value of that argument. The attributes of this object contains information about the event that triggered the listener. The gr.EventData object itself contains a .target attribute that refers to the component that triggered the event, while subclasses of gr.EventData contains additional attributes that are different for each class.

Example Usage

import gradio as gr

with gr.Blocks() as demo:
    table = gr.Dataframe([[1, 2, 3], [4, 5, 6]])
    gallery = gr.Gallery([("cat.jpg", "Cat"), ("dog.jpg", "Dog")])
    textbox = gr.Textbox("Hello World!")
    statement = gr.Textbox()

    def on_select(value, evt: gr.EventData):
        return f"The {evt.target} component was selected, and its value was {value}."

    table.select(on_select, table, statement)
    gallery.select(on_select, gallery, statement)
    textbox.select(on_select, textbox, statement)

demo.launch()

Attributes

Parameters
target: Block | None

The component object that triggered the event. Can be used to distinguish multiple components bound to the same listener.

Demos