The primary distinction between
mo.ui.dictionary
and a standard Python dictionary lies in how they handle UI elements. In
mo.ui.dictionary
, each UI element is a clone of the original, meaning interactions with elements in
mo.ui.dictionary
do not affect the original elements—and vice versa.
As demonstrated in the video, interacting with the original UI elements updates the corresponding values in the Python dictionary, but not in
mo.ui.dictionary
.
This allows you to reuse multiple UI components (e.g., sliders, text inputs, or date pickers) independently, ensuring they don’t interfere with each other when managed through
mo.ui.dictionary
.
However, if you use a regular Python dictionary, all references remain synchronized, and changes to one element propagate across all linked instances.
Additionally,
mo.ui.dictionary
makes it easy to apply convenient styling options. For example:
mo.ui.dictionary(
{f"option {i}": mo.ui.slider(1, 10, show_value=True) for i in range(10)}
).vstack() # Can also use .hstack(), .callout(), .center(), etc.
This structure enables quick, organized layouts like vertical or horizontal stacks, callouts, and centering, enhancing UI design without extra complexity.