This docs on this page refers to a PREVIOUS VERSION. For the latest stable release, go to https://docs.bokeh.org/

Archived docs for versions <= 1.0.4 have had to be modified from their original published configuration, and may be missing some features (e.g. source listing)

All users are encourage to update to version 1.1 or later, as soon as they are able.

bokeh.models.widgets.buttons — Bokeh 1.0.2 documentation

Source code for bokeh.models.widgets.buttons

''' Various kinds of button widgets.

'''
from __future__ import absolute_import

from ...core.enums import ButtonType
from ...core.has_props import abstract, HasProps
from ...core.properties import Bool, Enum, Instance, Int, List, Override, String, Tuple

from ..callbacks import Callback

from .icons import AbstractIcon
from .widget import Widget

[docs]@abstract class ButtonLike(HasProps): ''' Shared properties for button-like widgets. ''' button_type = Enum(ButtonType, help=""" A style for the button, signifying it's role. """)
[docs]@abstract class AbstractButton(Widget, ButtonLike): ''' A base class that defines common properties for all button types. ''' label = String("Button", help=""" The text label for the button to display. """) icon = Instance(AbstractIcon, help=""" An optional image appearing to the left of button's text. """) callback = Instance(Callback, help=""" A callback to run in the browser whenever the button is activated. """)
[docs]class Button(AbstractButton): ''' A click button. ''' clicks = Int(0, help=""" A private property used to trigger ``on_click`` event handler. """)
[docs] def on_click(self, handler): ''' Set up a handler for button clicks. Args: handler (func) : handler function to call when button is clicked. Returns: None ''' self.on_change('clicks', lambda attr, old, new: handler())
[docs] def js_on_click(self, handler): ''' Set up a JavaScript handler for button clicks. ''' self.js_on_change('clicks', handler)
[docs]class Toggle(AbstractButton): ''' A two-state toggle button. ''' label = Override(default="Toggle") active = Bool(False, help=""" The initial state of a button. Also used to trigger ``on_click`` event handler. """)
[docs] def on_click(self, handler): """ Set up a handler for button state changes (clicks). Args: handler (func) : handler function to call when button is toggled. Returns: None """ self.on_change('active', lambda attr, old, new: handler(new))
[docs] def js_on_click(self, handler): """ Set up a JavaScript handler for button state changes (clicks). """ self.js_on_change('active', handler)