← All notes

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

Inputs and outputs

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

Sources

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

Permanent ID: iil:note:828d2mbd

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.},
}

Markdown

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.

All artifact files (JSON index)

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.