DearPyGui is a modern, fast and powerful GUI framework for Python that provides an easy-to-use, dynamic, GPU-accelerated, cross-platform graphical user interface toolkit.
—
Comprehensive event system for user interactions including mouse events, keyboard input, and item-specific callbacks. DearPyGui provides both global event handlers and item-specific event handling.
def add_handler_registry(*, tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Creates a registry for global event handlers."""
def add_item_handler_registry(*, tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Creates a registry for item-specific event handlers."""def add_mouse_click_handler(*, button: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles mouse click events."""
def add_mouse_down_handler(*, button: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles mouse button press events."""
def add_mouse_release_handler(*, button: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles mouse button release events."""
def add_mouse_move_handler(*, callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles mouse movement events."""
def add_mouse_drag_handler(*, button: int = '', threshold: float = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles mouse drag events."""def add_key_press_handler(*, key: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles key press events."""
def add_key_down_handler(*, key: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles key down events."""
def add_key_release_handler(*, key: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles key release events."""def add_item_clicked_handler(*, button: int = '', callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles item click events."""
def add_item_hover_handler(*, callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles item hover events."""
def add_item_focus_handler(*, callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles item focus events."""
def add_item_edited_handler(*, callback: Callable = '', tag: Union[int, str] = '', **kwargs) -> Union[int, str]:
"""Handles item edit events."""
def add_item_activated_handler(*, label: str = '', user_data: Any = '', use_internal_label: bool = '', tag: Union[int, str] = '', parent: Union[int, str] = '', callback: Callable = '', show: bool = '') -> Union[int, str]:
"""
Handles item activation events (double-click or Enter key).
Parameters:
- callback (Callable): Function to call when item is activated
Returns:
Union[int, str]: Handler ID
"""
def add_item_deactivated_handler(*, label: str = '', user_data: Any = '', use_internal_label: bool = '', tag: Union[int, str] = '', parent: Union[int, str] = '', callback: Callable = '', show: bool = '') -> Union[int, str]:
"""
Handles item deactivation events.
Parameters:
- callback (Callable): Function to call when item is deactivated
Returns:
Union[int, str]: Handler ID
"""
def add_item_visible_handler(*, label: str = '', user_data: Any = '', use_internal_label: bool = '', tag: Union[int, str] = '', parent: Union[int, str] = '', callback: Callable = '', show: bool = '') -> Union[int, str]:
"""
Handles item visibility change events.
Parameters:
- callback (Callable): Function to call when item visibility changes
Returns:
Union[int, str]: Handler ID
"""
def add_item_toggled_open_handler(*, label: str = '', user_data: Any = '', use_internal_label: bool = '', tag: Union[int, str] = '', parent: Union[int, str] = '', callback: Callable = '', show: bool = '') -> Union[int, str]:
"""
Handles toggle events for collapsible items.
Parameters:
- callback (Callable): Function to call when item is toggled
Returns:
Union[int, str]: Handler ID
"""def is_mouse_button_down(button: int) -> bool:
"""Checks if mouse button is currently pressed."""
def is_mouse_button_clicked(button: int) -> bool:
"""Checks if mouse button was clicked this frame."""
def is_mouse_button_double_clicked(button: int) -> bool:
"""Checks if mouse button was double-clicked this frame."""
def is_mouse_button_released(button: int) -> bool:
"""Checks if mouse button was released this frame."""
def is_mouse_button_dragging(button: int, threshold: float) -> bool:
"""
Checks if mouse button is being dragged.
Parameters:
- button (int): Mouse button constant
- threshold (float): Minimum drag distance
Returns:
bool: True if dragging
"""
def is_key_down(key: int) -> bool:
"""Checks if key is currently pressed."""
def get_mouse_pos() -> Union[List[int], Tuple[int, ...]]:
"""Gets current mouse position."""
def get_mouse_drag_delta(button: int = '', lock_threshold: float = '') -> Union[List[float], Tuple[float, ...]]:
"""Gets mouse drag distance."""def set_frame_callback(frame: int, callback: Callable, *, user_data: Any = '') -> str:
"""
Sets a callback to execute at a specific frame number.
Parameters:
- frame (int): Frame number to execute callback
- callback (Callable): Function to call
- user_data (Any): Data to pass to callback
Returns:
str: Callback ID
"""
def capture_next_item(callback: Callable, *, user_data: Any = '') -> None:
"""
Captures the next item created and passes it to callback.
Parameters:
- callback (Callable): Function to receive captured item
- user_data (Any): Data to pass to callback
"""import dearpygui.dearpygui as dpg
def on_key_press(sender, key):
print(f"Key pressed: {key}")
def on_mouse_click(sender, button):
pos = dpg.get_mouse_pos()
print(f"Mouse clicked at {pos}")
def on_button_clicked(sender):
print(f"Button {sender} was clicked!")
# Create handler registry
with dpg.handler_registry():
dpg.add_key_press_handler(callback=on_key_press)
dpg.add_mouse_click_handler(callback=on_mouse_click)
# Window with widgets
with dpg.window(label="Event Example", width=400, height=300):
dpg.add_text("Press keys or click mouse")
dpg.add_button(label="Click Me!", callback=on_button_clicked)# Mouse buttons
mvMouseButton_Left: int
mvMouseButton_Right: int
mvMouseButton_Middle: int
# Key codes
mvKey_A: int
mvKey_B: int
# ... (full key set available)Install with Tessl CLI
npx tessl i tessl/pypi-dearpygui