Button
selectors.Button
Creates a Run Button selector. It runs the block has the button and the following blocks.
| Parameter | Description | Default |
|---|---|---|
| selector_name | The name of the selector. It must be unique. | - |
| label | The label for the button. If not passed the button will show the selector_name. | - |
| exclude_run_self | If True, the button will execute all blocks but the current one. | False |
| reset_selectors | Specify a list of any other selector ids in the same block, to reset them from any user change. See the last code example below. | [] |
| width | Custom css width property. | False |
| help_text | Tooltip help message displayed while the input is focused. | - |
| size | Define the size of the button, could be small, middle or large. | middle |
| button_color | custom button text color. | - |
| background | custom button background color. | - |
| block_uuid | Optional 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.