{"library":"pysdl2","title":"PySDL2","description":"PySDL2 provides comprehensive Python bindings for the SDL2 (Simple DirectMedia Layer) C library, along with its various extensions (SDL_image, SDL_mixer, SDL_ttf, SDL_gfx). It allows Python developers to create cross-platform multimedia applications, games, and graphical user interfaces. The current version is 0.9.17, with releases typically tied to updates in the underlying SDL2 library, though the pace has slowed as focus shifts towards SDL3 development.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pysdl2"],"cli":null},"imports":["import sdl2","import sdl2.ext","import sdl2.sdlimage","import sdl2.sdlmixer","import sdl2.sdlttf"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import sdl2\nimport sdl2.ext\n\nRESOURCES = sdl2.ext.Resources(__file__, 'resources')\n\ndef run():\n    sdl2.ext.init()\n\n    window = sdl2.ext.Window(\"My PySDL2 Window\", size=(800, 600))\n    window.show()\n\n    # Create a software renderer for the window\n    # Note: For hardware acceleration, you'd typically use sdl2.render.create_renderer\n    # and potentially integrate with OpenGL/Vulkan via PyOpenGL.\n    renderer = sdl2.ext.Renderer(window)\n\n    running = True\n    while running:\n        events = sdl2.ext.get_events()\n        for event in events:\n            if event.type == sdl2.SDL_QUIT:\n                running = False\n                break\n        \n        # Clear the window to black\n        renderer.clear(sdl2.ext.Color(0, 0, 0))\n        # You can add drawing commands here\n        # renderer.draw_rect(..., sdl2.ext.Color(255, 0, 0))\n        \n        renderer.present()\n        window.refresh()\n\n    sdl2.ext.quit()\n    return 0\n\nif __name__ == '__main__':\n    import sys\n    sys.exit(run())","lang":"python","description":"This quickstart initializes SDL2 using `sdl2.ext`, creates a basic window, sets up a software renderer, and implements a simple event loop to handle closing the window. It demonstrates the high-level `sdl2.ext` API for common operations. Remember to install native SDL2 libraries on your system before running this code.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}