Checkbox¶
Bases: InputElement
_value_type: type
property
¶
Get the Checkbox value type: boolean bool
.
__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, kwargs)
¶
A simple checkbox with a label. Value is either True, False or None.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
ID of the element. It must be unique as it is the key used to story data in
Project(), otherwise it will lead to conflicts at runtime in both execution and
Streamlit modes. The key will be transformed into snake case and slugified to avoid
any special character or whitespace. Note that an ID cannot start with |
required |
value |
Optional[Union[bool, List[bool]]]
|
Initial check status: True, False or None. |
required |
label |
Optional[str]
|
Label to display next to the checkbox. |
None
|
count |
Optional[Union[int, str]]
|
Specify the number of occurence of the widget. OneCode typically uses it for the
streamlit case. Note that if |
None
|
optional |
Union[bool, str]
|
Specify whether the value may be None. |
False
|
hide_when_disabled |
bool
|
If element is optional, set it to True to hide it from the interface, otherwise it will be shown disabled. |
False
|
**kwargs |
Any
|
Extra user meta-data to attach to the element. Argument names cannot overwrite
existing attributes or methods name such as |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if the |
AttributeError
|
if one the |
Example
from onecode import checkbox, Mode, Project
Project().mode = Mode.EXECUTE
widget = checkbox(
key="Checkbox",
value=True,
label="My Checkbox"
)
print(widget)
True
_validate(value)
¶
No validation is performed.
streamlit(id)
¶
Returns:
Type | Description |
---|---|
str
|
The Streamlit code for a checkbox ( |