Skip to content

Commit 4182a28

Browse files
committed
doc: added example, module docs for behaviors/togglebutton.py
1 parent 45a03bf commit 4182a28

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

kivy/uix/behaviors/togglebutton.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,45 @@
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()
243
'''
344

445
__all__ = ('ToggleButtonBehavior', )
@@ -10,8 +51,9 @@
1051

1152
class ToggleButtonBehavior(ButtonBehavior):
1253
'''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.
1557
1658
.. versionadded:: 1.8.0
1759
'''

0 commit comments

Comments
 (0)