Introducing Gradio Clients

Watch

New to Gradio? Start here: Getting Started

See the Release History

Button

gradio.Button(···)
import gradio as gr with gr.Blocks() as demo: gr.Button() demo.launch()

Description

Creates a button that can be assigned arbitrary .click() events. The value (label) of the button can be used as an input to the function (rarely used) or set via the output of a function.

Behavior

As input component: (Rarely used) the str corresponding to the button label when the button is clicked

Your function should accept one of these types:
def predict(
	value: str | None
)
	...

As output component: string corresponding to the button label

Your function should return one of these types:
def predict(···) -> str | None
	...	
	return value

Initialization

Parameters

Shortcuts

Class Interface String Shortcut Initialization

gradio.Button

"button"

Uses default values

gradio.ClearButton

"clearbutton"

Uses default values

gradio.DuplicateButton

"duplicatebutton"

Uses default values

gradio.LoginButton

"loginbutton"

Uses default values

gradio.LogoutButton

"logoutbutton"

Uses default values

Event Listeners

Description

Event listeners allow you to respond to user interactions with the UI components you've defined in a Gradio Blocks app. When a user interacts with an element, such as changing a slider value or uploading an image, a function is called.

Supported Event Listeners

The Button component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below.

Listener Description

Button.click(fn, ···)

Triggered when the Button is clicked.

Event Parameters

Parameters