Press❖

Module path❖
kivydk.uix.behavior.press

Overview❖

Provides pointer‑based press and release detection for widgets. PressBehavior listens to pointer events routed through the KiviDK PointerManager and dispatches on_press and on_release whenever a pointer button is pressed or released.

A press event is fired immediately when a pointer button is pressed. A release event is fired when the button released, and includes an inside flag indicating whether the release occurred within the widget’s bounds.


Example❖

Sample demonstrating how PressBehavior can be used to detect press and release actions on a widget.

../../../_images/TestPress.gif
 1#// IMPORT
 2from kivy.uix.label import Label
 3
 4from kivydk.uix.behavior import PressBehavior
 5
 6
 7#// LOGIC
 8class TestPress(PressBehavior, Label):
 9    """ Each event updates the label text to reflect the current press state. """
10    def __init__(self, **kwargs):
11        super().__init__(**kwargs)
12
13        # Provide the default label context
14        self.text = "Press Example"
15        self.font_size = "18 dp"
16
17    def on_press(self, button, modifiers):
18        self.text = f"The {button!r} button was pressed."
19
20    def on_release(self, button, modifiers, inside):
21        self.text = f"The {button!r} button was released {'inside' if inside else 'outside'}."
22
23
24#// RUN FILE
25if __name__ == "__main__":
26    from kivydk.app import App
27
28    class Example(App):
29        def build(self):
30            return TestPress(size_hint_y=None, height=256)
31
32    Example().run()

Reference❖

class PressBehavior(**kwargs)❖

Bases: object

A mixin that adds basic press and release detection to any widget.

Note

This behavior is intentionally lightweight and does not implement click logic. For click detection, use ClickBehavior.

Events

Todo

The current event implementation relies on __events__ being defined as a class attribute. This works for now, but it overrides inherited Kivy events.

When revisiting the event system, consider migrating to register_event_type() and updating the DocLang command to support dynamically registered events.

on_press

Fired when a pointer button is pressed.

on_release

Fired when a pointer button is released.

on_press(button: str | None, modifiers: list[str]) → None❖

Fired when a pointer button is pressed.

Parameters

Name

Description

button

The name of the pointer button that triggered the event, or None.

modifiers

A list of active modifier keys (e.g. alt, ctrl, shift, numlock).

on_release(button: str | None, modifiers: list[str], inside: bool) → None❖

Fired when a pointer button is released.

Parameters

Name

Description

button

The name of the pointer button that triggered the event, or None.

modifiers

A list of active modifier keys (e.g. alt, ctrl, shift, numlock).

inside

True if the release occurred inside the widget, False otherwise.