CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dearpygui

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.

Pending
Overview
Eval results
Files

application-lifecycle.mddocs/

Application Lifecycle

Core application management functions for DearPyGui applications. These functions control the application lifecycle from initialization through the main loop to cleanup. Every DearPyGui application must use these functions in the proper sequence.

Capabilities

Context Management

Context creation and destruction manages the global application state and resources.

def create_context() -> None:
    """
    Creates the DearPyGui context. Must be called before any other DearPyGui functions.
    
    This initializes the global state, memory allocators, and core systems.
    Only one context can exist at a time.
    """

def destroy_context() -> None:
    """
    Destroys the DearPyGui context and cleans up all resources.
    
    This should be called at the end of your application to ensure
    proper cleanup of GPU resources, memory, and platform handles.
    """

Usage Example

import dearpygui.dearpygui as dpg

# Initialize DearPyGui
dpg.create_context()

# Your application code here
# ...

# Cleanup when done
dpg.destroy_context()

Viewport Management

Viewport functions manage the main application window and its properties.

def create_viewport(*, title: str = '', width: int = '', height: int = '', x_pos: int = '', y_pos: int = '', min_width: int = '', min_height: int = '', max_width: int = '', max_height: int = '', resizable: bool = '', vsync: bool = '', always_on_top: bool = '', decorated: bool = '', clear_color: Union[List[float], Tuple[float, ...]] = '', small_icon: str = '', large_icon: str = '') -> None:
    """
    Creates the main application viewport (window).
    
    Parameters:
    - title (str): Window title
    - width, height (int): Initial window size
    - x_pos, y_pos (int): Initial window position
    - min_width, min_height (int): Minimum window size
    - max_width, max_height (int): Maximum window size  
    - resizable (bool): Allow window resizing
    - vsync (bool): Enable vertical sync
    - always_on_top (bool): Keep window on top
    - decorated (bool): Show window decorations (title bar, etc.)
    - clear_color (tuple): Background clear color as (r, g, b, a)
    - small_icon, large_icon (str): Icon file paths
    """

def show_viewport() -> None:
    """
    Makes the viewport visible. Call after create_viewport() and setup_dearpygui().
    """

def maximize_viewport() -> None:
    """Maximizes the viewport window."""

def minimize_viewport() -> None:
    """Minimizes the viewport window."""

def toggle_viewport_fullscreen() -> None:
    """Toggles fullscreen mode for the viewport."""

def is_viewport_ok() -> bool:
    """
    Checks if the viewport is valid and not closed.
    
    Returns:
    bool: True if viewport is still valid
    """

Application Setup and Control

Core setup and control functions for running the application.

def setup_dearpygui() -> None:
    """
    Completes DearPyGui setup. Call after creating context and viewport,
    but before showing viewport and starting the main loop.
    
    This initializes the rendering backend and prepares the application
    for display.
    """

def start_dearpygui() -> None:
    """
    Starts the DearPyGui main loop. This is a blocking call that runs
    until the application is closed.
    
    Equivalent to:
    while dpg.is_dearpygui_running():
        dpg.render_dearpygui_frame()
    """

def stop_dearpygui() -> None:
    """
    Stops the DearPyGui main loop. Can be called from within the application
    to programmatically exit.
    """

def is_dearpygui_running() -> bool:
    """
    Checks if DearPyGui is currently running.
    
    Returns:
    bool: True if the main loop should continue
    """

def render_dearpygui_frame() -> None:
    """
    Renders a single frame. Use this for custom main loops instead of
    start_dearpygui() when you need more control over the execution.
    """

def split_frame() -> None:
    """
    Splits the current frame processing. Advanced usage for custom
    render loops with timing control.
    """

Configuration Functions

Application-wide configuration and settings.

def configure_app(*, manual_callback_management: bool = '', load_init_file: str = '', init_file: str = '', auto_save_init_file: bool = '', auto_device: bool = '', device: int = '', allow_alias_overwrites: bool = '', auto_render_delay_time: int = '', skip_required_args: bool = '', skip_positional_args: bool = '', skip_keyword_args: bool = '', wait_for_input: bool = '', docking: bool = '', docking_space: bool = '') -> None:
    """
    Configures global application settings.
    
    Parameters:
    - manual_callback_management (bool): Disable automatic callback processing
    - load_init_file (str): Load settings from file on startup
    - init_file (str): Settings file path
    - auto_save_init_file (bool): Automatically save settings on exit
    - auto_device (bool): Automatically select graphics device
    - device (int): Specific graphics device index
    - allow_alias_overwrites (bool): Allow alias name collisions
    - auto_render_delay_time (int): Delay between render calls (ms)
    - skip_required_args (bool): Skip required argument validation
    - skip_positional_args (bool): Skip positional argument validation  
    - skip_keyword_args (bool): Skip keyword argument validation
    - wait_for_input (bool): Wait for user input before rendering
    - docking (bool): Enable window docking
    - docking_space (bool): Create docking space
    """

def get_app_configuration() -> dict:
    """
    Gets current application configuration.
    
    Returns:
    dict: Configuration settings dictionary
    """

def configure_viewport(item: Union[int, str], *, title: str = '', width: int = '', height: int = '', x_pos: int = '', y_pos: int = '', min_width: int = '', min_height: int = '', max_width: int = '', max_height: int = '', resizable: bool = '', vsync: bool = '', always_on_top: bool = '', decorated: bool = '', clear_color: Union[List[float], Tuple[float, ...]] = '', small_icon: str = '', large_icon: str = '') -> None:
    """
    Configures viewport properties after creation.
    
    Parameters: Same as create_viewport()
    """

def get_viewport_configuration() -> dict:
    """
    Gets current viewport configuration.
    
    Returns:
    dict: Viewport settings dictionary
    """

Callback Management

Advanced callback system control for custom event handling.

def set_frame_callback(frame: int, callback: Callable) -> None:
    """
    Sets a callback to be executed on a specific frame.
    
    Parameters:
    - frame (int): Frame number to execute callback
    - callback (Callable): Function to call
    """

def set_exit_callback(callback: Callable) -> None:
    """
    Sets a callback to be executed when the application exits.
    
    Parameters:
    - callback (Callable): Function to call on exit
    """

def set_viewport_resize_callback(callback: Callable) -> None:
    """
    Sets a callback for viewport resize events.
    
    Parameters:
    - callback (Callable): Function to call with (sender, width, height)
    """

def get_callback_queue() -> list:
    """
    Gets the current callback queue for manual processing.
    
    Returns:
    list: List of pending callbacks
    """

def run_callbacks(jobs: list) -> None:
    """
    Manually processes a list of callbacks.
    
    Parameters:
    - jobs (list): List of callback jobs to process
    """

System Information

Functions to get system and runtime information.

def get_platform() -> int:
    """
    Gets the current platform identifier.
    
    Returns:
    int: Platform constant (Windows=0, Linux=1, Apple=2)
    """

def get_frame_count() -> int:
    """
    Gets the current frame number.
    
    Returns:
    int: Number of frames rendered since start
    """

def get_frame_rate() -> float:
    """
    Gets the current frame rate in FPS.
    
    Returns:
    float: Frames per second
    """

def get_delta_time() -> float:
    """
    Gets the time elapsed since the last frame.
    
    Returns:
    float: Delta time in seconds
    """

def get_total_time() -> float:
    """
    Gets the total time since application start.
    
    Returns:
    float: Total elapsed time in seconds
    """

Application Patterns

Common application structure patterns for different use cases.

Basic Application Pattern

import dearpygui.dearpygui as dpg

# Setup
dpg.create_context()
dpg.create_viewport(title="My App", width=800, height=600)
dpg.setup_dearpygui()

# Create UI
with dpg.window(label="Main Window", width=400, height=300):
    dpg.add_text("Hello, DearPyGui!")
    dpg.add_button(label="Click Me!")

# Run
dpg.show_viewport()
dpg.start_dearpygui()

# Cleanup
dpg.destroy_context()

Custom Main Loop Pattern

import dearpygui.dearpygui as dpg

# Setup
dpg.create_context()
dpg.create_viewport(title="Custom Loop", width=800, height=600)
dpg.setup_dearpygui()

# Create UI
with dpg.window(label="Main Window"):
    dpg.add_text("Custom main loop example")

# Custom main loop
dpg.show_viewport()
while dpg.is_dearpygui_running():
    # Custom logic here
    frame_time = dpg.get_delta_time()
    
    # Process callbacks manually if needed
    # dpg.run_callbacks(dpg.get_callback_queue())
    
    # Render frame
    dpg.render_dearpygui_frame()

dpg.destroy_context()

Configuration Example

import dearpygui.dearpygui as dpg

dpg.create_context()

# Configure application
dpg.configure_app(
    docking=True,
    docking_space=True,
    auto_device=True,
    wait_for_input=False
)

# Configure viewport
dpg.create_viewport(
    title="Configured App",
    width=1200,
    height=800,
    min_width=400,
    min_height=300,
    resizable=True,
    vsync=True,
    clear_color=(0.1, 0.1, 0.1, 1.0)
)

dpg.setup_dearpygui()

# Create dockable windows
with dpg.window(label="Window 1", width=300, height=200):
    dpg.add_text("Dockable window 1")

with dpg.window(label="Window 2", width=300, height=200):
    dpg.add_text("Dockable window 2")

dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

Error Handling

Application lifecycle functions may raise exceptions for:

  • Context errors: Calling functions before create_context() or after destroy_context()
  • Viewport errors: Invalid viewport parameters or calling viewport functions without a viewport
  • Resource errors: Graphics device initialization failures
  • Platform errors: Platform-specific window creation failures

Always wrap application lifecycle calls in try-catch blocks for production applications:

import dearpygui.dearpygui as dpg

try:
    dpg.create_context()
    dpg.create_viewport(title="Safe App", width=800, height=600)
    dpg.setup_dearpygui()
    
    # Your UI code here
    
    dpg.show_viewport()
    dpg.start_dearpygui()
    
except Exception as e:
    print(f"Application error: {e}")
    
finally:
    if dpg.is_dearpygui_running():
        dpg.destroy_context()

Performance Considerations

  • Call create_context() only once per application
  • Use configure_app() before setup_dearpygui() for best performance
  • Enable vsync for smoother animations: create_viewport(vsync=True)
  • Use wait_for_input=True for applications that don't need continuous rendering
  • Consider auto_render_delay_time for applications with heavy processing

Platform-Specific Notes

Windows

  • Supports DirectX 11/12 backends for best performance
  • Window icons should be .ico format
  • DPI awareness is handled automatically

macOS

  • Uses Metal backend
  • Window icons should be .icns format
  • Retina display support is automatic

Linux

  • Uses OpenGL backend
  • Window icons should be .png format
  • X11 and Wayland support

Install with Tessl CLI

npx tessl i tessl/pypi-dearpygui

docs

advanced.md

application-lifecycle.md

drawing.md

events.md

index.md

layout.md

plotting.md

tables.md

widgets.md

tile.json