bundles / traitlets 5.14.3 / traitlets / traitlets / HasTraits / on_trait_change
function
traitlets.traitlets:HasTraits.on_trait_change
source: /traitlets/traitlets.py :1596
Signature
def on_trait_change ( self , handler : EventHandler | None = None , name : Sentinel | str | None = None , remove : bool = False ) → None Summary
DEPRECATED: Setup a handler to be called when a trait changes.
Extended Summary
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention '_[traitname]_changed'. Thus, to create static handler for the trait 'a', create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
Parameters
handler: callable, NoneA callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
name: list, str, NoneIf None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
remove: boolIf False (the default), then install the handler. If True then unintall it.
Aliases
-
traitlets.HasTraits.on_trait_change