NiceGUI: Bind visibility to arbitrary value
All notes in this series:
- NiceGUI: Always show main scrollbar
- NiceGUI: Show a confirmation popup
- NiceGUI: File upload and download
- FastAPI: Pretty print JSON
- NiceGUI with Click, Poetry, auto-reload and classes
- NiceGUI: tkinter error when updating pyplot
- NiceGUI: Bind visibility to arbitrary value
- NiceGUI: Change threshold for binding propagation warning
- NiceGUI with async classes
NiceGUI gives lots of examples of using bind_visibility_from
to show/hide an element based upon the value of some attribute.
For example:
However, they all assuume you only want visibility when the value is True
. What if you want it when the value is False
, or some other arbitrary value?
For that you use the backward
keyword argument, which specifies a function that takes the value of the attribute, and should return a truthy value.
Visible when False
§
To invert the above example so that the label is only visible when the checkbox is not ticked:
Visible upon arbitrary value §
Or to use an arbitrary value:
There are some examples of this in the NiceGUI code base.