Introducing Gradio Clients

Watch

New to Gradio? Start here: Getting Started

See the Release History

Textbox

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

Description

Creates a textarea for user to enter string input or display string output.

Behavior

As input component: Passes text value as a str into the function.

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

As output component: Expects a str returned from function and sets textarea value to it.

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

Initialization

Parameters

Shortcuts

Class Interface String Shortcut Initialization

gradio.Textbox

"textbox"

Uses default values

gradio.TextArea

"textarea"

Uses lines=7

Demos

import gradio as gr def greet(name): return "Hello " + name + "!" demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox") if __name__ == "__main__": demo.launch()

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 Textbox component supports the following event listeners. Each event listener takes the same parameters, which are listed in the Event Parameters table below.

Listener Description

Textbox.change(fn, ···)

Triggered when the value of the Textbox changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See .input() for a listener that is only triggered by user input.

Textbox.input(fn, ···)

This listener is triggered when the user changes the value of the Textbox.

Textbox.select(fn, ···)

Event listener for when the user selects or deselects the Textbox. Uses event data gradio.SelectData to carry value referring to the label of the Textbox, and selected to refer to state of the Textbox. See EventData documentation on how to use this event data

Textbox.submit(fn, ···)

This listener is triggered when the user presses the Enter key while the Textbox is focused.

Textbox.focus(fn, ···)

This listener is triggered when the Textbox is focused.

Textbox.blur(fn, ···)

This listener is triggered when the Textbox is unfocused/blurred.

Event Parameters

Parameters

Guides