- Helpers
- SelectData
New to Gradio? Start here: Getting Started
See the Release History
SelectData
gradio.SelectData(···)Description
The gr.SelectData class is a subclass of gr.EventData that specifically carries information about the .select() event. When gr.SelectData is added as a type hint to an argument of an event listener method, a gr.SelectData 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.
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(evt: gr.SelectData):
return f"You selected {evt.value} at {evt.index} from {evt.target}"
table.select(on_select, None, statement)
gallery.select(on_select, None, statement)
textbox.select(on_select, None, statement)
demo.launch()Attributes
Parameters
index: int | tuple[int, int]
index: int | tuple[int, int]The index of the selected item. Is a tuple if the component is two dimensional or selection is a range.
row_value: list[float | str]
row_value: list[float | str]The value of the entire row that the selected item belongs to, as a 1-D list. Only implemented for the `Dataframe` component, returns None for other components.