Table Of Contents
Behaviors¶
New in version 1.8.0.
This module implements behaviors that can be mixed with existing base widgets. For example, if you want to add a “button” capability to an Image, you could do:
class IconButton(ButtonBehavior, Image):
pass
Note
The behavior class must always be _before_ the widget class. If you don’t specify the inheritance in this order, the behavior will not work.
- class kivy.uix.behaviors.ButtonBehavior(**kwargs)[source]¶
Bases: object
Button behavior.
Events: - on_press
Fired when the button is pressed.
- on_release
Fired when the button is released (i.e. the touch/click that pressed the button goes away).
- last_touch¶
Contains the last relevant touch received by the Button. This can be used in on_press or on_release in order to know which touch dispatched the event.
New in version 1.8.0.
last_touch is a ObjectProperty, defaults to None.
- state¶
State of the button, must be one of ‘normal’ or ‘down’. The state is ‘down’ only when the button is currently touched/clicked, otherwise ‘normal’.
state is an OptionProperty.
- trigger_action(duration=0.1)[source]¶
Trigger whatever action(s) have been bound to the button by calling both the on_press and on_release callbacks.
This simulates a quick button press without using any touch events.
Duration is the length of the press in seconds. Pass 0 if you want the action to happen instantly.
New in version 1.8.0.
- class kivy.uix.behaviors.ToggleButtonBehavior(**kwargs)[source]¶
Bases: kivy.uix.behaviors.ButtonBehavior
ToggleButton behavior, see ToggleButton module documentation for more information.
New in version 1.8.0.
- static get_widgets(groupname)[source]¶
Return the widgets contained in a specific group. If the group doesn’t exist, an empty list will be returned.
Important
Always release the result of this method! In doubt, do:
l = ToggleButtonBehavior.get_widgets('mygroup') # do your job del l
Warning
It’s possible that some widgets that you have previously deleted are still in the list. Garbage collector might need more elements before flushing it. The return of this method is informative, you’ve been warned!
- group¶
Group of the button. If None, no group will be used (button is independent). If specified, group must be a hashable object, like a string. Only one button in a group can be in ‘down’ state.
group is a ObjectProperty
- class kivy.uix.behaviors.DragBehavior(**kwargs)[source]¶
Bases: object
Drag behavior. When combined with a widget, dragging in the rectangle defined by drag_rectangle will drag the widget.
For example, to make a popup which is draggable by its title do:
from kivy.uix.behaviors import DragBehavior from kivy.uix.popup import Popup class DragPopup(DragBehavior, Popup): pass
- And in .kv do::
- <DragPopup>:
- drag_rectangle: self.x, self.y+self._container.height, self.width, self.height - self._container.height drag_timeout: 10000000 drag_distance: 0
New in version 1.8.0.
- drag_distance¶
Distance to move before dragging the DragBehavior, in pixels. As soon as the distance has been traveled, the DragBehavior will start to drag, and no touch event will go to children. It is advisable that you base this value on the dpi of your target device’s screen.
drag_distance is a NumericProperty, defaults to 20 (pixels), according to the default value of scroll_distance in user configuration.
- drag_rect_height¶
Height of the axis aligned bounding rectangle where dragging is allowed.
drag_rect_height is a NumericProperty, defaults to 100.
- drag_rect_width¶
Width of the axis aligned bounding rectangle where dragging is allowed.
drag_rect_width is a NumericProperty, defaults to 100.
- drag_rect_x¶
X position of the axis aligned bounding rectangle where dragging is allowed. In window coordinates.
drag_rect_x is a NumericProperty, defaults to 0.
- drag_rect_y¶
Y position of the axis aligned bounding rectangle where dragging is allowed. In window coordinates.
drag_rect_Y is a NumericProperty, defaults to 0.
- drag_rectangle¶
Position and size of the axis aligned bounding rectangle where dragging is allowed.
drag_rectangle is a ReferenceListProperty of (drag_rect_x, drag_rect_y, drag_rect_width, drag_rect_height) properties.
- drag_timeout¶
Timeout allowed to trigger the drag_distance, in milliseconds. If the user has not moved drag_distance within the timeout, dragging will be disabled, and the touch event will go to the children.
drag_timeout is a NumericProperty, defaults to 55 (milliseconds), according to the default value of scroll_timeout in user configuration.