hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en
MIT License
13.03k stars 678 forks source link

Question: Adding DearPyGui to existing imgui C++ application with an embedded Python interpreter #2322

Open sebasth opened 5 months ago

sebasth commented 5 months ago

Is there a way to use this library in existing C++ imgui project. I have an embedded Python interpreter in my program and would like to call python code from C++ to draw additional gui widgets, something like:

my_python_gui.py

def my_py_gui():
    with dpg.window(label="Example Window"):
            dpg.add_text("Hello world")
            dpg.add_button(label="Save", callback=save_callback)
            dpg.add_input_text(label="string")
            dpg.add_slider_float(label="float")

and rendering loop in C++ (with pybind11):

...

ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
...
// C++ imgui
...
// Python imgui (assuming the above python script previously loaded)
py::exec("my_py_gui()");
...
ImGui::Render();