Cython-based Python bindings for dear imgui - a bloat-free immediate mode graphical user interface library
npx @tessl/cli install tessl/pypi-imgui@2.0.0Python bindings for the amazing Dear ImGui C++ library - a bloat-free immediate mode graphical user interface toolkit. ImGui enables Python developers to create modern GUI applications with a simple, immediate-mode paradigm where UI elements are defined in code and rendered on-demand, making it ideal for tools, debugging interfaces, games, and rapid prototyping.
pip install imgui[full] (includes all rendering backends)Basic imgui import provides access to all core functionality:
import imguiFor integration with specific rendering backends:
from imgui.integrations.glfw import GlfwRenderer
from imgui.integrations.pygame import PygameRenderer
from imgui.integrations.pyglet import PygletRenderer
from imgui.integrations.sdl2 import SDL2Rendererimport imgui
import glfw
from imgui.integrations.glfw import GlfwRenderer
import OpenGL.GL as gl
def main():
# Initialize the rendering backend
imgui.create_context()
window = init_glfw() # Your GLFW window setup
impl = GlfwRenderer(window)
# Main application loop
while not glfw.window_should_close(window):
glfw.poll_events()
impl.process_inputs()
# Start new ImGui frame
imgui.new_frame()
# Create a simple window
if imgui.begin("Hello, ImGui!"):
imgui.text("This is a simple ImGui window")
if imgui.button("Click me!"):
print("Button was clicked!")
# Input widgets
text_value = imgui.input_text("Enter text:", "default")[1]
slider_value = imgui.slider_float("Slider", 0.0, 0.0, 1.0)[1]
# Color picker
color = imgui.color_edit4("Color", 1.0, 0.0, 0.0, 1.0)
imgui.end()
# Render
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
imgui.render()
impl.render(imgui.get_draw_data())
glfw.swap_buffers(window)
impl.shutdown()
if __name__ == "__main__":
main()ImGui follows an immediate mode design pattern with these key components:
The immediate mode approach means no widget objects are retained - UI is rebuilt every frame based on application state, making it extremely simple to create dynamic, reactive interfaces.
Essential functions for initializing and managing ImGui contexts. These functions are critical for proper ImGui setup and cleanup.
def create_context() -> None: ...
def destroy_context() -> None: ...
def get_current_context(): ...
def set_current_context(context) -> None: ...
def get_io(): ...
def get_style(): ...
def new_frame() -> None: ...
def end_frame() -> None: ...
def render() -> None: ...
def get_draw_data(): ...
def show_demo_window(closable: bool = False) -> None: ...
def show_metrics_window(closable: bool = False) -> None: ...
def show_about_window(closable: bool = False) -> None: ...
def show_user_guide() -> None: ...
def get_version() -> str: ...Essential window operations including creating, positioning, sizing, and managing window states. Windows are the fundamental containers for all ImGui content.
def begin(label: str, closable: bool = False, flags: int = 0) -> bool: ...
def end() -> None: ...
def set_next_window_size(width: float, height: float, condition: int = ALWAYS) -> None: ...
def set_next_window_position(x: float, y: float, condition: int = ALWAYS, pivot_x: float = 0, pivot_y: float = 0) -> None: ...Comprehensive collection of interactive UI elements including buttons, text inputs, sliders, checkboxes, combo boxes, color pickers, and more. These widgets handle user input and return their current state.
def button(label: str, width: float = 0, height: float = 0) -> bool: ...
def input_text(label: str, value: str, buffer_length: int, flags: int = 0) -> tuple[bool, str]: ...
def slider_float(label: str, value: float, v_min: float, v_max: float, format: str = "%.3f") -> tuple[bool, float]: ...
def checkbox(label: str, state: bool) -> tuple[bool, bool]: ...Tools for controlling widget placement, spacing, grouping, and alignment. Includes cursor positioning, same-line placement, indentation, and grouping functions.
def same_line(position: float = 0.0, spacing: float = -1.0) -> None: ...
def separator() -> None: ...
def spacing() -> None: ...
def indent(width: float = 0.0) -> None: ...Mouse and keyboard input handling, item state queries, and focus management. Provides detailed information about user interactions with widgets and windows.
def is_item_hovered(flags: int = 0) -> bool: ...
def is_item_clicked(mouse_button: int = 0) -> bool: ...
def is_key_pressed(key_index: int, repeat: bool = False) -> bool: ...
def get_mouse_pos() -> tuple[float, float]: ...Comprehensive styling system for customizing colors, spacing, fonts, and visual appearance. Supports style stacks, color themes, and custom styling.
def push_style_color(variable: int, r: float, g: float, b: float, a: float = 1.0) -> None: ...
def pop_style_color(count: int = 1) -> None: ...
def push_style_var(variable: int, value: float) -> None: ...
def style_colors_dark() -> None: ...Modern table system with sorting, resizing, reordering, and scrolling capabilities. Ideal for displaying structured data with interactive features.
def begin_table(label: str, column: int, flags: int = 0) -> bool: ...
def table_setup_column(label: str, flags: int = 0, init_width_or_weight: float = 0.0) -> None: ...
def table_next_row() -> None: ...
def table_next_column() -> bool: ...Complete menu bar and popup menu functionality for creating application menus, context menus, and modal dialogs.
def begin_main_menu_bar() -> bool: ...
def begin_menu(label: str, enabled: bool = True) -> bool: ...
def menu_item(label: str, shortcut: str = "", selected: bool = False, enabled: bool = True) -> tuple[bool, bool]: ...
def begin_popup(label: str, flags: int = 0) -> bool: ...Tab bar system for organizing content into multiple views with support for reordering, closing, and dynamic tab management.
def begin_tab_bar(identifier: str, flags: int = 0) -> bool: ...
def begin_tab_item(label: str, opened: bool = None, flags: int = 0) -> tuple[bool, bool]: ...
def tab_item_button(label: str, flags: int = 0) -> bool: ...Low-level drawing capabilities for custom graphics, shapes, text rendering, and advanced visual effects using draw lists.
def get_window_draw_list(): ...
def get_background_draw_list(): ...
class _DrawList:
def add_line(self, p1: tuple, p2: tuple, color: int, thickness: float = 1.0) -> None: ...
def add_rect(self, p_min: tuple, p_max: tuple, color: int, rounding: float = 0.0) -> None: ...Python-specific helper functions and utilities that extend ImGui's functionality with convenient features for Python developers.
from imgui import extra
def extra.text_ansi(text: str) -> None: ...
def extra.text_ansi_colored(text: str) -> None: ...
def extra.font(font_object): ...
def extra.styled(style_vars: dict): ...
def extra.colored(color_vars: dict): ...
def extra.vertex_buffer_vertex_pos_offset() -> int: ...
def extra.vertex_buffer_vertex_uv_offset() -> int: ...
def extra.vertex_buffer_vertex_col_offset() -> int: ...
def extra.vertex_buffer_vertex_size() -> int: ...
def extra.index_buffer_index_size() -> int: ...Low-level internal ImGui functions for advanced use cases and custom widget development. Use with caution as these APIs may change between versions.
from imgui import internal
def internal.push_item_flag(option: int, enabled: bool) -> None: ...
def internal.pop_item_flag() -> None: ...Renderer integrations for various graphics libraries and frameworks including GLFW, SDL2, Pygame, Pyglet, and Cocos2D.
class GlfwRenderer:
def __init__(self, window) -> None: ...
def process_inputs() -> None: ...
def render(draw_data) -> None: ...