Gradio Blocks builds custom apps from components wired together by event listeners
Answer: The Blocks app code is contained within a with gr.Blocks() as demo: clause, and event listeners such as click() tie input and output components to a function. Event listeners define the data flow within the app; components created inside the clause are added to the Blocks automatically.
Example
import gradio as gr
def greet(name):
return "Hello " + name + "!"
with gr.Blocks() as demo:
name = gr.Textbox(label="Name")
output = gr.Textbox(label="Output Box")
greet_btn = gr.Button("Greet")
greet_btn.click(fn=greet, inputs=name, outputs=output, api_name="greet")
name.submit(fn=greet, inputs=name, outputs=output).then(lambda: "", outputs=name)
demo.launch()
Event listeners
click()is triggered when a Button is clicked;change()is triggered by typing in a Textbox. Different Components support different event listeners, likeplay()onVideo..then()runs the next event after the previous one finishes, regardless of errors..success()runs it only if the previous event succeeded, and.failure()only if it raised an error.gr.on(triggers=[...], fn=...)binds multiple triggers to the same function, such as a submit button and pressing enter. With no triggers, it binds to thechangeevents of the input components.
Inputs and outputs
- A function can take inputs as a list of arguments or as a single dictionary keyed by the component.
- It can return a list of values, one per output component, or a dictionary keyed by the component.
Interactivity
Any Component that acts as an input to an event listener is made interactive, and an output-only component is not. Override this with interactive=True or interactive=False. A component that is neither input nor output is non-interactive if constructed with a default value.
See also
Claims
- id: C1 claim: Event listeners define the data flow within the app. source: S1 evidence: "Event listeners define the data flow within the app."
- id: C2 claim: .then() runs the next event regardless of errors. source: S2 evidence: "executes the subsequent event regardless of whether the previous event raised any errors"
- id: C3 claim: Input components are made interactive. source: S2 evidence: "any Component that acts as an input to an event listener is made interactive"
Sources
- [S1] Blocks and Event Listeners. Gradio guides. https://www.gradio.app/guides/blocks-and-event-listeners . License: Apache-2.0. Accessed 2026-11-18.
- [S2] Blocks and Event Listeners (source page). gradio-app/gradio (GitHub). https://github.com/gradio-app/gradio/blob/main/guides/03_building-with-blocks/01_blocks-and-event-listeners.md . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Gradio guides, Blocks and Event Listeners; gradio-app/gradio (GitHub), Blocks and Event Listeners (source page). Apache-2.0 (https://raw.githubusercontent.com/gradio-app/gradio/main/LICENSE). Copyright Gradio authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Gradio guides, Blocks and Event Listeners; gradio-app/gradio (GitHub), Blocks and Event Listeners (source page). Apache-2.0 (https://raw.githubusercontent.com/gradio-app/gradio/main/LICENSE). Copyright Gradio authors.
Cite this
iinventedlight. 2026. "Gradio Blocks builds custom apps from components wired together by event listeners." iinventedlight Library, iil:note:828d2mbd, version of 2026-11-18. https://iinventedlight.com/library/notes/gradio-blocks/. License: CC-BY-4.0.
@misc{iil_note_828d2mbd,
author = {{iinventedlight}},
title = {{Gradio Blocks builds custom apps from components wired together by event listeners}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/gradio-blocks/},
note = {Permanent ID iil:note:828d2mbd. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- gradio-blocks.table.json (table; CC-BY-4.0)
- gradio-blocks.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/gradio-blocks.md.