Skip to main content

Button

selectors.Button

Creates a Run Button selector. It runs the block has the button and the following blocks.

ParameterDescriptionDefault
selector_nameThe name of the selector. It must be unique.-
labelThe label for the button. If not passed the button will show the selector_name.-
exclude_run_selfIf True, the button will execute all blocks but the current one.False
reset_selectorsSpecify a list of any other selector ids in the same block, to reset them from any user change. See the last code example below.[]
widthCustom css width property.False
help_textTooltip help message displayed while the input is focused.-
sizeDefine the size of the button, could be small, middle or large.middle
button_colorcustom button text color.-
backgroundcustom button background color.-
block_uuidOptional value to specify the block that will be executed when the selector triggers execution.(current block uuid)

Examples:

sel = selectors.Dropdown("dropdown_0", options=['apple', 'pear'], options_names=['Apple', 'Pear'], label='Select a value')
sel.render()
print("You have selected", sel.value)
sel = selectors.Button("btn_0", label='Go!')
sel.render()
print("Btn was clicked:", sel.value)
from IPython.display import display, HTML
elements =[]
button = selectors.Button(
'btn-1',
label='Button 1 with helptext',
help_text='Click to submit',
)
elements.append(button)

button = selectors.Button(
'btn-2',
label='Button 2 with colors',
background='#ffcccc',
color='red',
size="middle"
)
elements.append(button)

button = selectors.Button(
'btn-3',
label='Button 3 only color',
color='red',
size="large"
)
elements.append(button)


elements_html = "".join(
f'<tr><td>{element}</td><td>{element.value}</td></tr>'
for element in elements
)

display(HTML(f"""
<table>
<td></td><td>clicked</td>
{elements_html}
</table>
"""))

Reset other selectors in the same block

Pressing the button you can also specify a list of any other selector ids in the same block, to reset them to their initial state.

See code example below.

# Reset other selectors in the same block

# Button wich will also reset sel-
select_b = selectors.Button('button-11', label='Will reset Sel-A', reset_selectors=['sel-A'])
select_b.render()

options = list(range(10))
sel_A = selectors.Dropdown('sel-A', options)
value = sel_A.value
sel_A.render()
print("value of sel A:", value)

See also

  • All selector types — the full catalog of available selector controls.
  • Selectors — common arguments and how to define, render, and read selectors.