### Create Viewport, Setup, Show, and Start DPG Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/tutorials/dpg-structure.rst This snippet demonstrates the basic setup for a DPG application, including context creation, defining a window with UI elements, creating and showing the viewport, setting up DearPyGui, and starting the render loop. It concludes with destroying the context for cleanup. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Example Window"): dpg.add_text("Hello, world") dpg.add_button(label="Save") dpg.add_input_text(label="string", default_value="Quick brown fox") dpg.add_slider_float(label="float", default_value=0.273, max_value=1) dpg.create_viewport(title='Custom Title', width=600, height=200) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Dear PyGui Setup and Main Loop Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/file-directory-selector.rst Standard Dear PyGui setup, including creating the viewport, setting up the GUI, showing the viewport, and starting the main loop. Ensure `dpg.destroy_context()` is called after the loop finishes. ```python dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Build Hello World Example Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/CMakeLists.txt Builds the 'hello' executable example. It links against the imnodes library, SDL2, and platform-specific OpenGL libraries. ```cmake add_executable(hello ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/hello.cpp) target_link_libraries(hello imnodes SDL2::SDL2) if (APPLE) target_link_libraries(hello "-framework OpenGL") elseif(MSVC) target_link_libraries(hello "opengl32") else() target_link_libraries(hello X11 Xext GL) endif() ``` -------------------------------- ### Build Save/Load Example Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/CMakeLists.txt Builds the 'saveload' executable example. It links against the imnodes library, SDL2, and platform-specific OpenGL libraries. ```cmake add_executable(saveload ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/save_load.cpp) target_link_libraries(saveload imnodes SDL2::SDL2) if (APPLE) target_link_libraries(saveload "-framework OpenGL") elseif(MSVC) target_link_libraries(saveload "opengl32") else() target_link_libraries(saveload X11 Xext GL) endif() ``` -------------------------------- ### Build Examples Option Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/CMakeLists.txt Sets the IMNODES_EXAMPLES option, which controls whether example projects are built. It defaults to the value of IMNODES_STANDALONE_PROJECT. ```cmake option(IMNODES_EXAMPLES "Build examples" ${IMNODES_STANDALONE_PROJECT}) ``` -------------------------------- ### Build imnodes Examples with CMake Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/README.md Build the imnodes examples using CMake and vcpkg. Ensure the vcpkg submodule is initialized before running the CMake commands. ```bash git submodule update --init cmake -B build-release/ -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake cmake --build build-release -- -j ``` -------------------------------- ### Build Multi-Editor Example Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/CMakeLists.txt Builds the 'multieditor' executable example. It links against the imnodes library, SDL2, and platform-specific OpenGL libraries. ```cmake add_executable(multieditor ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/multi_editor.cpp) target_link_libraries(multieditor imnodes SDL2::SDL2) if (APPLE) target_link_libraries(multieditor "-framework OpenGL") elseif(MSVC) target_link_libraries(multieditor "opengl32") else() target_link_libraries(multieditor X11 Xext GL) endif() ``` -------------------------------- ### Install Dear PyGui Extensions Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/DearPyGui_Ext/README.md Use pip to install the dearpygui_ext package. Ensure you have Python 3.6 64bit and Dear PyGui installed. ```bash pip install dearpygui_ext or pip3 install dearpygui_ext ``` -------------------------------- ### Install Dear PyGui Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/tutorials/first-steps.rst Install Dear PyGui using pip. Ensure you have Python 3.6 or above. ```bash pip install dearpygui ``` -------------------------------- ### Apply Theme to Specific Item Type Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/themes.rst This snippet shows the basic setup for Dear PyGui context and window creation, with a single input text item. It serves as a base for applying item-specific themes, although the theme application itself is not fully shown in this truncated example. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1: t1 = dpg.add_input_text(default_value="some text") ``` -------------------------------- ### Create a Basic Dear PyGui Table Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/tables.rst This is the minimum example for creating a table in Dear PyGui. It demonstrates adding columns and populating cells with text. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial"): with dpg.table(header_row=False): # use add_table_column to add columns to the table, # table columns use child slot 0 dpg.add_table_column() dpg.add_table_column() dpg.add_table_column() # add_table_next_column will jump to the next row # once it reaches the end of the columns # table next column use slot 1 for i in range(0, 4): with dpg.table_row(): for j in range(0, 3): dpg.add_text(f"Row{i} Column{j}") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Build Color Node Editor Example Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/CMakeLists.txt Builds the 'colornode' executable example. It links against the imnodes library, SDL2, and platform-specific OpenGL libraries. ```cmake find_package(SDL2 CONFIG REQUIRED) add_executable(colornode ${CMAKE_CURRENT_SOURCE_DIR}/imnodes.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/example/color_node_editor.cpp) target_link_libraries(colornode imnodes SDL2::SDL2) if (APPLE) target_link_libraries(colornode "-framework OpenGL") elseif(MSVC) target_link_libraries(colornode "opengl32") else() target_link_libraries(colornode X11 Xext GL) endif() ``` -------------------------------- ### Install Dear PyGui Source: https://github.com/hoffstadt/dearpygui/blob/master/README.md Install Dear PyGui using pip. Ensure you have Python 3.8 64bit or newer. ```bash pip install dearpygui or pip3 install dearpygui ``` -------------------------------- ### Run Your First Dear PyGui App Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/tutorials/first-steps.rst Create a basic Dear PyGui application with a window, text, button, input field, and slider. This example demonstrates the fundamental structure of a DPG application. ```python import dearpygui.dearpygui as dpg dpg.create_context() dpg.create_viewport(title='Custom Title', width=600, height=300) with dpg.window(label="Example Window"): dpg.add_text("Hello, world") dpg.add_button(label="Save") dpg.add_input_text(label="string", default_value="Quick brown fox") dpg.add_slider_float(label="float", default_value=0.273, max_value=1) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Viewport Menu Bar Example Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/menus.rst Demonstrates creating a viewport menu bar with nested menus and various widget items. Ensure DPG context and viewport are created before defining the menu bar. ```python import dearpygui.dearpygui as dpg def print_me(sender): print(f"Menu Item: {sender}") dpg.create_context() dpg.create_viewport(title='Custom Title', width=600, height=200) with dpg.viewport_menu_bar(): with dpg.menu(label="File"): dpg.add_menu_item(label="Save", callback=print_me) dpg.add_menu_item(label="Save As", callback=print_me) with dpg.menu(label="Settings"): dpg.add_menu_item(label="Setting 1", callback=print_me, check=True) dpg.add_menu_item(label="Setting 2", callback=print_me) dpg.add_menu_item(label="Help", callback=print_me) with dpg.menu(label="Widget Items"): dpg.add_checkbox(label="Pick Me", callback=print_me) dpg.add_button(label="Press Me", callback=print_me) dpg.add_color_picker(label="Color Me", callback=print_me) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Menu Bar Example Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/menus.rst Illustrates creating a menu bar attached to a specific window, including nested menus and widget items. Requires DPG context and viewport creation. ```python import dearpygui.dearpygui as dpg dpg.create_context() dpg.create_viewport(title='Custom Title', width=600, height=200) def print_me(sender): print(f"Menu Item: {sender}") with dpg.window(label="Tutorial"): with dpg.menu_bar(): with dpg.menu(label="File"): dpg.add_menu_item(label="Save", callback=print_me) dpg.add_menu_item(label="Save As", callback=print_me) with dpg.menu(label="Settings"): dpg.add_menu_item(label="Setting 1", callback=print_me, check=True) dpg.add_menu_item(label="Setting 2", callback=print_me) dpg.add_menu_item(label="Help", callback=print_me) with dpg.menu(label="Widget Items"): dpg.add_checkbox(label="Pick Me", callback=print_me) dpg.add_button(label="Press Me", callback=print_me) dpg.add_color_picker(label="Color Me", callback=print_me) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Wrapping DPG Items in a Class (Window Example) Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/staging.rst Demonstrates staging a window item within a class. The `submit` method unstages the window, and `add_child` moves items into it. Note that the `Button` class in this example is incomplete and only shows its `__init__` method. ```python import dearpygui.dearpygui as dpg dpg.create_context() class Window: def __init__(self, label): self._children = [] with dpg.stage() as stage: self.id = dpg.add_window(label=label) self.stage = stage def add_child(self, child): dpg.move_item(child.id, parent=self.id) def submit(self): dpg.unstage(self.stage) class Button: def __init__(self, label): with dpg.stage(): self.id = dpg.add_button(label=label) def set_callback(self, callback): dpg.set_item_callback(self.id, callback) ``` -------------------------------- ### Basic Node Editor Example Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/node-editor.rst Demonstrates the creation of a simple node editor with two nodes, each having input and output attributes. Includes callbacks for handling link creation and deletion. ```python import dearpygui.dearpygui as dpg dpg.create_context() # callback runs when user attempts to connect attributes def link_callback(sender, app_data): # app_data -> (link_id1, link_id2) dpg.add_node_link(app_data[0], app_data[1], parent=sender) # callback runs when user attempts to disconnect attributes def delink_callback(sender, app_data): # app_data -> link_id dpg.delete_item(app_data) with dpg.window(label="Tutorial", width=400, height=400): with dpg.node_editor(callback=link_callback, delink_callback=delink_callback): with dpg.node(label="Node 1"): with dpg.node_attribute(label="Node A1"): dpg.add_input_float(label="F1", width=150) with dpg.node_attribute(label="Node A2", attribute_type=dpg.mvNode_Attr_Output): dpg.add_input_float(label="F2", width=150) with dpg.node(label="Node 2"): with dpg.node_attribute(label="Node A3"): dpg.add_input_float(label="F3", width=200) with dpg.node_attribute(label="Node A4", attribute_type=dpg.mvNode_Attr_Output): dpg.add_input_float(label="F4", width=200) dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Basic Popup Example Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/popups.rst Demonstrates how to create a simple popup that appears when an item is right-clicked. The popup is attached to the last item created in the window. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial"): dpg.add_text("Right Click Me") with dpg.popup(dpg.last_item()): dpg.add_text("A popup") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Apply Theme to a Container Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/themes.rst This example shows how to create a theme and bind it to a specific container (a window in this case), causing it to propagate to its children. It customizes styles for all item types and input integers within that container. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1: t1 = dpg.add_input_text(default_value="some text") t2 = dpg.add_input_text(default_value="some text") with dpg.child_window(height=100): t3 = dpg.add_input_text(default_value="some text") dpg.add_input_int() dpg.add_input_text(default_value="some text") with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2: dpg.add_input_text(default_value="some text") dpg.add_input_int() with dpg.theme() as container_theme: with dpg.theme_component(dpg.mvAll): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (150, 100, 100), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) with dpg.theme_component(dpg.mvInputInt): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (100, 150, 100), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) dpg.bind_item_theme(win1, container_theme) dpg.show_style_editor() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Theme Priority Example Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/themes.rst Illustrates the theme priority in Dear PyGui: specific item, container inherited, and global. This example defines three themes (global, container, and item) and binds them to demonstrate how they override each other. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1: t1 = dpg.add_input_text(default_value="some text") t2 = dpg.add_input_text(default_value="some text") with dpg.child_window(height=100): t3 = dpg.add_input_text(default_value="some text") dpg.add_input_int() dpg.add_input_text(default_value="some text") with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2: dpg.add_input_text(default_value="some text") dpg.add_input_int() with dpg.theme() as global_theme: with dpg.theme_component(dpg.mvAll): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (255, 140, 23), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) with dpg.theme_component(dpg.mvInputInt): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (140, 255, 23), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) with dpg.theme() as container_theme: with dpg.theme_component(dpg.mvAll): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (150, 100, 100), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) with dpg.theme_component(dpg.mvInputInt): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (100, 150, 100), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) with dpg.theme() as item_theme: with dpg.theme_component(dpg.mvAll): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (200, 200, 100), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 0, category=dpg.mvThemeCat_Core) dpg.bind_theme(global_theme) dpg.bind_item_theme(win1, container_theme) dpg.bind_item_theme(t2, item_theme) dpg.show_style_editor() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create Tab Bar with Context Manager Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/extra/video-tutorials.rst Illustrates creating a tab bar and its tabs using context managers. Includes examples of adding buttons to a tab bar and making tabs reorderable. ```python with tab_bar('tb1'): with tab('t1'): add_button('b1') ``` ```python with tab_bar('tb1', callback=callback) ``` ```python add_tab_button('+') ``` ```python with tab_bar('tb1', reorderable=True) ``` -------------------------------- ### Create Popup with Callback Source: https://github.com/hoffstadt/dearpygui/wiki/Video-Tutorials Example of creating a popup window that requires a parent widget. Popups can contain any other widget and can be configured to open on specific mouse clicks. ```python with popup('popup1', mousebutton=mvMouseButtonLeft): add_text('This is inside the popup') add_button('Close', callback=close_popup('popup1')) ``` -------------------------------- ### Sparse Clone and Checkout for Docs Source: https://github.com/hoffstadt/dearpygui/wiki/ReadTheDocs Use this method to clone only the documentation directory for faster setup or a cleaner local environment. Requires Git version 2.25 or higher. ```bash git clone --sparse https://github.com/hoffstadt/DearPyGui.git DearPyGui.docs cd DearPyGui.Docs git sparse-checkout set docs ``` -------------------------------- ### Basic Dear PyGui Application Source: https://github.com/hoffstadt/dearpygui/blob/master/README.md A simple Dear PyGui application demonstrating window creation, text, buttons, input fields, and sliders. This script requires the dearpygui library to be installed. ```python import dearpygui.dearpygui as dpg def save_callback(): print("Save Clicked") dpg.create_context() dpg.create_viewport() dpg.setup_dearpygui() 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") dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create and Display a Static Texture Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/textures.rst Use static textures for images that do not change often. They are loaded at startup and can be updated by deleting and recreating them. This example demonstrates creating a static texture and displaying it in a window. ```python import dearpygui.dearpygui as dpg dpg.create_context() texture_data = [] for i in range(0, 100 * 100): texture_data.append(255 / 255) texture_data.append(0) texture_data.append(255 / 255) texture_data.append(255 / 255) with dpg.texture_registry(show=True): dpg.add_static_texture(width=100, height=100, default_value=texture_data, tag="texture_tag") with dpg.window(label="Tutorial"): dpg.add_image("texture_tag") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Manual Render Loop in DPG Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/tutorials/dpg-structure.rst This example shows how to implement a manual render loop in DPG, which is useful for executing code on every frame, such as updates or tickers. The manual loop replaces the default `start_dearpygui()` and requires `render_dearpygui_frame()` to be called explicitly within a `while dpg.is_dearpygui_running():` loop. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Example Window"): dpg.add_text("Hello, world") dpg.add_button(label="Save") dpg.add_input_text(label="string", default_value="Quick brown fox") dpg.add_slider_float(label="float", default_value=0.273, max_value=1) dpg.create_viewport(title='Custom Title', width=600, height=200) dpg.setup_dearpygui() dpg.show_viewport() # below replaces, start_dearpygui() while dpg.is_dearpygui_running(): # insert here any code you would like to run in the render loop # you can manually stop by using stop_dearpygui() print("this will run every frame") dpg.render_dearpygui_frame() dpg.destroy_context() ``` -------------------------------- ### Configure GLFW Build Options Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/CMakeLists.txt Sets build options for the GLFW library to disable documentation, examples, tests, and installation. This is typically used to streamline the build process for dependencies. ```cmake set(GLFW_BUILD_DOCS OFF) set(GLFW_BUILD_EXAMPLES OFF) set(GLFW_BUILD_TESTS OFF) set(GLFW_INSTALL OFF) ``` -------------------------------- ### Save and Load Dear PyGui Init File Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/init-files.rst Demonstrates how to save the current Dear PyGui application state to an init file and load it on startup. Ensure window tags are consistent between sessions. ```python import dearpygui.dearpygui as dpg dpg.create_context() def save_init(): dpg.save_init_file("dpg.ini") dpg.configure_app(init_file="dpg.ini") # default file is 'dpg.ini' with dpg.window(label="about", tag="main window"): dpg.add_button(label="Save Window pos", callback=lambda: save_init) with dpg.window(label="about", tag="side window"): dpg.add_button(label="Press me") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Commit Message Example Source: https://github.com/hoffstadt/dearpygui/wiki/General-Guidelines An example of a commit message following the specified format, indicating a fix for a button double-click issue. ```text fix (mvButton): fix button double-click melting user's monitor ``` -------------------------------- ### Create and Manage a Window Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/staging.rst Shows how to create a window, add child elements like buttons to it, and submit the window for display. This is a fundamental step in structuring the GUI. ```python my_window = Window("Tutorial") my_window.add_child(my_button) my_window.submit() ``` -------------------------------- ### Modal Popup Example Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/popups.rst Shows how to create a modal popup that blocks interaction with other windows until it is closed. This example uses a left-click to activate the popup and provides a button to close it. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial"): dpg.add_text("Left Click Me") # check out simple module for details with dpg.popup(dpg.last_item(), mousebutton=dpg.mvMouseButton_Left, modal=True, tag="modal_id"): dpg.add_button(label="Close", callback=lambda: dpg.configure_item("modal_id", show=False)) dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create Windows using Context Managers Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/item-creation.rst Use context managers to create window items and initialize the DearPyGui application. This is the recommended approach for container creation. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Window1", pos=(0,0)): pass with dpg.window(label="Window2", pos=(100,0)): pass dpg.create_viewport(title='Custom Title', width=600, height=200) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Embed Simple Plot in Tooltip Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/extra/video-tutorials.rst Provides a concise example of embedding a simple plot within a tooltip widget. Note that tooltips are not interactive. ```python with tooltip('tooltip_id'): add_simple_plot('Plot 1', value=[1, 4.3, 8, 9, 3]) ``` -------------------------------- ### Configure Item After Creation Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/item-configuration.rst Use `configure_item` to modify an item's properties after it has been created. This example changes the enabled state and label of a button. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(width=500, height=300): dpg.add_button(enabled=True, label="Press me", tag="item") # at a later time, change the item's configuration dpg.configure_item("item", enabled=False, label="New Label") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Run the Dear PyGui Demo Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/tutorials/first-steps.rst Launch the built-in Dear PyGui demo application to explore its features. This requires importing the demo module. ```python import dearpygui.dearpygui as dpg import dearpygui.demo as demo dpg.create_context() dpg.create_viewport(title='Custom Title', width=600, height=600) demo.show_demo() dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Run Dear PyGui Demo Source: https://github.com/hoffstadt/dearpygui/blob/master/README.md Execute the built-in demo to explore Dear PyGui's functionality. This command launches the full demo application. ```bash python -m dearpygui.demo ``` -------------------------------- ### Get Selected Nodes Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/README.md Retrieve a list of currently selected nodes. First, query the number of selected nodes, then populate a vector with their IDs. ```cpp // Note that since many nodes can be selected at once, we first need to query the number of // selected nodes before getting them. const int num_selected_nodes = ImNodes::NumSelectedNodes(); if (num_selected_nodes > 0) { std::vector selected_nodes; selected_nodes.resize(num_selected_nodes); ImNodes::GetSelectedNodes(selected_nodes.data()); } ``` -------------------------------- ### Setting Callbacks and User Data for Buttons Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/tutorials/item-usage.rst Demonstrates how to set callbacks and user data for buttons, both during creation and after. ```python import dearpygui.dearpygui as dpg dpg.create_context() def button_callback(sender, app_data, user_data): print(f"sender is: {sender}") print(f"app_data is: {app_data}") print(f"user_data is: {user_data}") with dpg.window(label="Tutorial"): # user data and callback set when button is created dpg.add_button(label="Apply", callback=button_callback, user_data="Some Data") # user data and callback set any time after button has been created btn = dpg.add_button(label="Apply 2", ) dpg.set_item_callback(btn, button_callback) dpg.set_item_user_data(btn, "Some Extra User Data") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create Simple Plot Source: https://github.com/hoffstadt/dearpygui/wiki/Video-Tutorials Example of creating a basic histogram using the add_simple_plot function. Various keywords can be used to customize the plot's appearance. ```python add_simple_plot(“Plot 1”, value=[1, 4.3, 8, 9, 3], histogram=True) ``` -------------------------------- ### Build Dear PyGui for Linux Source: https://github.com/hoffstadt/dearpygui/wiki/Building-For-Development Prepare and execute the build script for Dear PyGui on Linux. This involves making the script executable and then running it. ```bash chmod +x BuildPythonForLinux.sh ./BuildPythonForLinux.sh ``` -------------------------------- ### Check for Newly Created Links Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/README.md Detect if a new link was created during the current frame using `IsLinkCreated`. This function outputs the IDs of the start and end attributes. ```cpp int start_attr, end_attr; if (ImNodes::IsLinkCreated(&start_attr, &end_attr)) { links.push_back(std::make_pair(start_attr, end_attr)); } ``` -------------------------------- ### Configure and Build Dear PyGui with CMake on Linux Source: https://github.com/hoffstadt/dearpygui/wiki/Building-For-Development Set up the build directory and use CMake to configure and build Dear PyGui on Linux. This process involves creating a build directory, running CMake, and then building the project. ```bash mkdir cmake-build-debug cd cmake-build-debug cmake .. cd .. cmake --build cmake-build-debug --config Debug ``` -------------------------------- ### Build Dear PyGui for Windows Source: https://github.com/hoffstadt/dearpygui/wiki/Building-For-Development Execute the batch script to build the Python environment for Dear PyGui on Windows. Ensure Visual Studio with C++ development workloads is installed. ```batch Scripts\BuildPythonForWindows.bat ``` -------------------------------- ### Custom ImNodes Configuration Header Source: https://github.com/hoffstadt/dearpygui/blob/master/thirdparty/imnodes/README.md This example shows an imnodes_config.h header that defines custom types for the minimap hovering callback and its user data, useful for generating pybind wrappers. ```cpp #pragma once #include namespace pybind11 { inline bool PyWrapper_Check(PyObject *o) { return true; } class wrapper : public object { public: PYBIND11_OBJECT_DEFAULT(wrapper, object, PyWrapper_Check) wrapper(void* x) { m_ptr = (PyObject*)x; } explicit operator bool() const { return m_ptr != nullptr && m_ptr != Py_None; } }; } //namespace pybind11 namespace py = pybind11; #define ImNodesMiniMapNodeHoveringCallback py::wrapper #define ImNodesMiniMapNodeHoveringCallbackUserData py::wrapper ``` -------------------------------- ### Create and Configure Viewport Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/viewport.rst This snippet demonstrates the essential steps to create, configure, and display the DearPyGui viewport. It includes setting window titles, dimensions, and icons, along with platform-specific adjustments for Windows. ```python import sys import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Example Window", width=500, height=150): dpg.add_text("Hello, world") dpg.create_viewport(title='Custom Title', width=600, height=200) # create viewport takes in config options too! # must be called before showing viewport dpg.set_viewport_small_icon("path/to/icon.ico") dpg.set_viewport_large_icon("path/to/icon.ico") # On Windows it isn't possible to show the large Icon, because it gets overwritten by the OS. This line fixes this Issue. if sys.platform.startswith('win'): import ctypes ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID( u'CompanyName.ProductName.SubProduct.VersionInformation') dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create a Dear PyGui Window with Menus Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/container-context-manager.rst This snippet demonstrates the basic structure for creating a Dear PyGui application with a main window, menu bar, and nested menus. It uses the context manager approach for defining the UI hierarchy. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Main"): with dpg.menu_bar(): with dpg.menu(label="Themes"): dpg.add_menu_item(label="Dark") dpg.add_menu_item(label="Light") dpg.add_menu_item(label="Classic") with dpg.menu(label="Other Themes"): dpg.add_menu_item(label="Purple") dpg.add_menu_item(label="Gold") dpg.add_menu_item(label="Red") with dpg.menu(label="Tools"): dpg.add_menu_item(label="Show Logger") dpg.add_menu_item(label="Show About") with dpg.menu(label="Oddities"): dpg.add_button(label="A Button") dpg.add_simple_plot(label="Menu plot", default_value=(0.3, 0.9, 2.5, 8.9), height=80) dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Build Wheel for Windows (amd64) Source: https://github.com/hoffstadt/dearpygui/wiki/Local-Wheel Builds a wheel package for Windows 64-bit systems. Ensure Python development and C++ desktop/game development workflows are installed in Visual Studio 2019. ```bash python -m setup bdist_wheel --plat-name win_amd64 --dist-dir dist ``` -------------------------------- ### Create Simple Plots and Histograms Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/simple-plots.rst Demonstrates how to add basic line plots and histograms to a DearPyGui window. Requires `dearpygui.dearpygui` to be imported. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial", width=500, height=500): dpg.add_simple_plot(label="Simpleplot1", default_value=(0.3, 0.9, 0.5, 0.3), height=300) dpg.add_simple_plot(label="Simpleplot2", default_value=(0.3, 0.9, 2.5, 8.9), overlay="Overlaying", height=180, histogram=True) dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Apply Default Theme Globally Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/themes.rst This snippet demonstrates how to create a theme and bind it as the default theme, affecting all windows and items globally. It includes styling for all item types and specifically for input integers. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial", pos=(20, 50), width=275, height=225) as win1: t1 = dpg.add_input_text(default_value="some text") t2 = dpg.add_input_text(default_value="some text") with dpg.child_window(height=100): t3 = dpg.add_input_text(default_value="some text") dpg.add_input_int() dpg.add_input_text(default_value="some text") with dpg.window(label="Tutorial", pos=(320, 50), width=275, height=225) as win2: dpg.add_input_text(default_value="some text") dpg.add_input_int() with dpg.theme() as global_theme: with dpg.theme_component(dpg.mvAll): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (255, 140, 23), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) with dpg.theme_component(dpg.mvInputInt): dpg.add_theme_color(dpg.mvThemeCol_FrameBg, (140, 255, 23), category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) dpg.bind_theme(global_theme) dpg.show_style_editor() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create a Table with Selectable Cells Source: https://github.com/hoffstadt/dearpygui/blob/master/docs/source/documentation/tables.rst Demonstrates how to create a table with selectable cells and bind a theme to them. This is useful for interactive table UIs. ```python for i in range(15): with dpg.table_row(): for j in range(3): dpg.add_selectable(label=f"Row{i} Column{j}", callback=clb_selectable, user_data=(i,j)) dpg.bind_item_theme(selectablecells, table_theme) ```