|
1 |
| -'''See :class:`ToggleButtonBehavior` for details. |
| 1 | +''' |
| 2 | +ToggleButton Behavior |
| 3 | +===================== |
| 4 | +
|
| 5 | +The :class:`~kivy.uix.behaviors.togglebutton.ToggleButtonBehavior` |
| 6 | +`mixin <https://en.wikipedia.org/wiki/Mixin>`_ class provides |
| 7 | +:class:`~kivy.uix.togglebutton.ToggleButton` behavior. You can combine this |
| 8 | +class with other widgets, such as an :class:`~kivy.uix.image.Image`, to provide |
| 9 | +alternative togglebuttons that preserve Kivy togglebutton behavior. |
| 10 | +
|
| 11 | +For an overview of behaviors, please refer to the :mod:`~kivy.uix.behaviors` |
| 12 | +documentation. |
| 13 | +
|
| 14 | +Example |
| 15 | +------- |
| 16 | +
|
| 17 | +The following example adds togglebutton behavior to an image to make a checkbox |
| 18 | +that behaves like a togglebutton:: |
| 19 | +
|
| 20 | + from kivy.app import App |
| 21 | + from kivy.uix.image import Image |
| 22 | + from kivy.uix.behaviors import ToggleButtonBehavior |
| 23 | +
|
| 24 | +
|
| 25 | + class MyButton(ToggleButtonBehavior, Image): |
| 26 | + def __init__(self, **kwargs): |
| 27 | + super(MyButton, self).__init__(**kwargs) |
| 28 | + self.source = 'atlas://data/images/defaulttheme/checkbox_off' |
| 29 | +
|
| 30 | + def on_state(self, widget, value): |
| 31 | + if value == 'down': |
| 32 | + self.source = 'atlas://data/images/defaulttheme/checkbox_on' |
| 33 | + else: |
| 34 | + self.source = 'atlas://data/images/defaulttheme/checkbox_off' |
| 35 | +
|
| 36 | +
|
| 37 | + class SampleApp(App): |
| 38 | + def build(self): |
| 39 | + return MyButton() |
| 40 | +
|
| 41 | +
|
| 42 | + SampleApp().run() |
2 | 43 | '''
|
3 | 44 |
|
4 | 45 | __all__ = ('ToggleButtonBehavior', )
|
|
10 | 51 |
|
11 | 52 | class ToggleButtonBehavior(ButtonBehavior):
|
12 | 53 | '''This `mixin <https://en.wikipedia.org/wiki/Mixin>`_ class provides
|
13 |
| - :class:`~kivy.uix.togglebutton.ToggleButton` behavior. Please see |
14 |
| - the :mod:`~kivy.uix.togglebutton` module documentation for more information. |
| 54 | + :mod:`~kivy.uix.togglebutton` behavior. Please see the |
| 55 | + :mod:`togglebutton behaviors module <kivy.uix.behaviors.togglebutton>` |
| 56 | + documentation for more information. |
15 | 57 |
|
16 | 58 | .. versionadded:: 1.8.0
|
17 | 59 | '''
|
|
0 commit comments