The Checkbox component creates a boolean toggle that can be checked or unchecked.
Basic usage
import gradio as gr
def toggle_message(checked):
return "Checked!" if checked else "Unchecked"
gr.Interface(
fn=toggle_message,
inputs=gr.Checkbox(),
outputs=gr.Textbox()
).launch()
Constructor
value
bool | Callable
default:"False"
Whether checkbox is checked by default
Label displayed to the right of checkbox
Additional info text. Supports markdown/HTML
interactive
bool | None
default:"None"
Whether checkbox can be toggled
Events
- change - Triggered when checkbox state changes
- input - Triggered when checkbox is clicked
- select - Triggered when checkbox is selected
Example
import gradio as gr
def process_with_option(text, include_caps):
return text.upper() if include_caps else text
with gr.Blocks() as demo:
text_input = gr.Textbox(label="Enter text")
caps_check = gr.Checkbox(label="Convert to uppercase", value=False)
output = gr.Textbox(label="Result")
text_input.change(
fn=process_with_option,
inputs=[text_input, caps_check],
outputs=output
)
caps_check.change(
fn=process_with_option,
inputs=[text_input, caps_check],
outputs=output
)
demo.launch()