Quick search

Table Of Contents

ToggleButton Behavior

The ToggleButtonBehavior mixin class provides ToggleButton behavior. You can combine this class with other widgets, such as an Image, to provide alternative togglebuttons that preserve Kivy togglebutton behavior.

For an overview of behaviors, please refer to the behaviors documentation.

Example

The following example adds togglebutton behavior to an image to make a checkbox that behaves like a togglebutton:

from kivy.app import App
from kivy.uix.image import Image
from kivy.uix.behaviors import ToggleButtonBehavior


class MyButton(ToggleButtonBehavior, Image):
    def __init__(self, **kwargs):
        super(MyButton, self).__init__(**kwargs)
        self.source = 'atlas://data/images/defaulttheme/checkbox_off'

    def on_state(self, widget, value):
        if value == 'down':
            self.source = 'atlas://data/images/defaulttheme/checkbox_on'
        else:
            self.source = 'atlas://data/images/defaulttheme/checkbox_off'


class SampleApp(App):
    def build(self):
        return MyButton()


SampleApp().run()
class kivy.uix.behaviors.togglebutton.ToggleButtonBehavior(**kwargs)[ソース]

ベースクラス: kivy.uix.behaviors.button.ButtonBehavior

This mixin class provides togglebutton behavior. Please see the togglebutton behaviors module documentation for more information.

バージョン 1.8.0 で追加.

allow_no_selection

This specifies whether the widgets in a group allow no selection i.e. everything to be deselected.

バージョン 1.9.0 で追加.

allow_no_selection is a BooleanProperty and defaults to True

static get_widgets(groupname)[ソース]

Return a list of the widgets contained in a specific group. If the group doesn’t exist, an empty list will be returned.

注釈

Always release the result of this method! Holding a reference to any of these widgets can prevent them from being garbage collected. If in doubt, do:

l = ToggleButtonBehavior.get_widgets('mygroup')
# do your job
del l

警告

It’s possible that some widgets that you have previously deleted are still in the list. The garbage collector might need to release other objects before flushing them.

group

Group of the button. If None, no group will be used (the button will be independent). If specified, group must be a hashable object, like a string. Only one button in a group can be in a ‘down’ state.

group is a ObjectProperty and defaults to None.