{"library":"magicgui","title":"MagicGUI","description":"magicgui is a Python library that automatically generates graphical user interfaces (GUIs) from functions, primarily leveraging type hints for widget inference. It aims to make GUI creation simple and declarative, supporting various GUI backends (like Qt, wxPython, GTK, or custom) via `qtpy` and `app-model`. The current stable version is 0.10.2, with active development and frequent releases.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install magicgui","pip install magicgui[qt]"],"cli":null},"imports":["from magicgui import magicgui","from magicgui.widgets import Container","from magicgui.function_gui import FunctionGui"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport sys\nfrom magicgui import magicgui\nfrom magicgui.widgets import Container\n\n# Ensure a Qt application is running for the GUI to display\ntry:\n    from qtpy.QtWidgets import QApplication\n    app = QApplication.instance() # Use existing app if any\n    if app is None:\n        app = QApplication(sys.argv)\nexcept ImportError:\n    print(\"Install `pip install magicgui[qt]` for a complete experience.\")\n    sys.exit(1)\n\n@magicgui(auto_call=True, layout=\"horizontal\", result_widget=True)\ndef calculate_sum(a: int = 1, b: int = 2) -> int:\n    \"\"\"Calculates the sum of two numbers.\"\"\"\n    return a + b\n\n@magicgui(call_button=\"Display Message\")\ndef show_message(text: str = \"Hello, magicgui!\"):\n    \"\"\"Displays a message in the console.\"\"\"\n    print(f\"User message: {text}\")\n\n# Create a container to hold multiple magicgui functions\nmain_container = Container(widgets=[calculate_sum, show_message], labels=False)\nmain_container.show()\n\n# Start the Qt event loop if running as a standalone script\nif app is not None and app.exec_ is not None:\n    sys.exit(app.exec_())\n","lang":"python","description":"This quickstart demonstrates how to create two simple GUI elements using the `@magicgui` decorator: one for calculation and another for message display. It then combines them into a `Container` and shows the window. It also includes the necessary `QApplication` setup to make the GUI runnable as a standalone script, which is a common requirement.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}