The Button component creates a clickable button that triggers events.
Basic usage
import gradio as gr
def greet():
return "Hello!"
with gr.Blocks() as demo:
output = gr.Textbox()
btn = gr.Button("Click me")
btn.click(fn=greet, outputs=output)
demo.launch()
Constructor
value
str | Callable
default:"'Run'"
Button label text
variant
Literal['primary', 'secondary', 'stop', 'huggingface']
default:"'secondary'"
Button style:
"primary" - Main call-to-action
"secondary" - Subdued style
"stop" - Stop button
"huggingface" - HF branded style
size
Literal['sm', 'md', 'lg']
default:"'lg'"
Button size
icon
str | Path | None
default:"None"
URL or path to icon file to display
link_target
Literal['_self', '_blank', '_parent', '_top']
default:"'_self'"
Where to open the linked URL
Whether button is clickable
Events
- click - Triggered when button is clicked
Examples
import gradio as gr
btn = gr.Button("Submit", variant="primary")
With icon
import gradio as gr
btn = gr.Button(
"Download",
icon="https://huggingface.co/favicon.ico"
)
As link
import gradio as gr
btn = gr.Button(
"Visit Gradio",
link="https://gradio.app",
link_target="_blank"
)