### Run a Basic Dear PyGui Application Source: https://dearpygui.readthedocs.io/en/latest/_sources/tutorials/first-steps.rst This Python code demonstrates how to create a simple Dear PyGui application. It sets up the context and viewport, creates a window with basic widgets (text, button, input, slider), and starts the Dear PyGui event loop. This is a fundamental example for beginners. ```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() ``` -------------------------------- ### Create Viewport and Start DPG Application Source: https://dearpygui.readthedocs.io/en/latest/tutorials/dpg-structure This code snippet demonstrates the basic setup for a Dear PyGui application. It includes creating the context, defining a window with various UI elements, creating and showing the viewport, setting up Dear PyGui, and starting the render loop. Finally, it destroys 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() ``` -------------------------------- ### Install Dear PyGui using pip Source: https://dearpygui.readthedocs.io/en/latest/_sources/tutorials/first-steps.rst This command installs the Dear PyGui library using pip. Ensure you have Python 3.6 (64-bit) or above installed. ```bash pip install dearpygui ``` -------------------------------- ### Initialize and Run Dear PyGui Viewport Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/staging.rst This code segment details the necessary steps to initialize, set up, display, and start the Dear PyGui application viewport. It concludes with destroying the context after the application 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() ``` -------------------------------- ### Configure and Get State/Info for Dear PyGui Items Source: https://dearpygui.readthedocs.io/en/latest/tutorials/item-usage Shows how to configure Dear PyGui items, set their properties like label and width, and retrieve their state and information. It demonstrates using functions like `set_item_label`, `set_item_width`, and `show_item_registry`. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial"): # configuration set when button is created dpg.add_button(label="Apply", width=300) # user data and callback set any time after button has been created btn = dpg.add_button(label="Apply 2") dpg.set_item_label(btn, "Button 57") dpg.set_item_width(btn, 200) dpg.show_item_registry() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Get Total Time (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Returns the total elapsed time in seconds since the Dear PyGui application started. This can be useful for timing operations or creating animations. ```Python dearpygui.dearpygui.get_total_time()[source] Returns total time since Dear PyGui has started. Args: :returns: float ``` -------------------------------- ### Create and Run a Basic DPG Application Source: https://dearpygui.readthedocs.io/en/latest/_sources/tutorials/dpg-structure.rst This snippet demonstrates the fundamental steps to create and run a basic DearPyGui application. It includes context creation, setting up a window with basic UI elements, creating and showing the viewport, setting up DearPyGui, and starting the render loop. Proper cleanup is also shown. ```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() ``` -------------------------------- ### Create and Configure Dear PyGui Viewport Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/viewport.rst This Python code demonstrates the essential steps to create, configure, and display a viewport (window) using the Dear PyGui library. It covers creating the context, setting up a window, creating the viewport with a title and dimensions, assigning icons, and finally setting up and starting the Dear PyGui application. It also includes a platform-specific fix for Windows to ensure the application icon is displayed correctly. ```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() ``` -------------------------------- ### Community Video: Python App with Dear PyGui Source: https://dearpygui.readthedocs.io/en/latest/extra/video-tutorials Highlights a community-created video tutorial on building a complete Python application using Dear PyGui. The tutorial covers step-by-step development of a GUI, integration with other Python components, and features like displaying images, text, user input, and handling events. ```python # This is a placeholder for code that would be demonstrated in the community video. # The actual code would be extensive and cover various Dear PyGui functionalities. # Example snippet demonstrating basic window, text, and button creation: import dearpygui.dearpygui as dpg def button_callback(sender, data): print("Button clicked!") dpg.create_context() with dpg.window(label="Community App Example"): dpg.add_text("Welcome to the Dear PyGui App!") dpg.add_button("Click Me", callback=button_callback) # Further elements like image display, input fields, etc. would be added here. dpg.create_viewport(title='Dear PyGui Community App', width=500, height=300) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Get Mouse Position (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the current position of the mouse cursor. An optional 'local' parameter can be provided to get the position relative to the current viewport. ```Python dearpygui.dearpygui.get_mouse_pos(_** kwargs_)[source] Returns mouse position. Parameters **local** (_bool_ _,__optional_) – Returns Union[List[int], Tuple[int, …]] ``` -------------------------------- ### Run the Dear PyGui Demo Application Source: https://dearpygui.readthedocs.io/en/latest/_sources/tutorials/first-steps.rst This Python code launches the comprehensive Dear PyGui demo application. It requires importing both the main Dear PyGui library and the demo module. This demo is useful for exploring the full range of Dear PyGui's features and widgets. ```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() ``` -------------------------------- ### Get Plot Query Area and Rects (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the query area (deprecated) or the query rectangles of a plot. These functions are used to get information about user-defined regions or selections within a plot. ```Python (deprecated function) Returns the last/current query area of the plot. If no area is available [0, 0, 0, 0] will be returned. Parameters **plot** (_Union_ _[__int_ _,__str_ _]_) – Returns Union[List[float], Tuple[float, …]] dearpygui.dearpygui.get_plot_query_rects(_plot_)[source] Returns the query rects of the plot. Returns an array of array containing the top-left coordinates and bottom-right coordinates of the plot area. Parameters **plot** (_Union_ _[__int_ _,__str_ _]_) – Returns List[List[float]] ``` -------------------------------- ### Scroll Information Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Functions to get scroll information for a given item. ```APIDOC ## GET /item/{item_id}/scroll/x ### Description Gets the current horizontal scroll position of a specified item. ### Method GET ### Endpoint /item/{item_id}/scroll/x ### Parameters #### Path Parameters - **item_id** (Union[int, str]) - Required - The ID or tag of the item to get the scroll position for. ### Response #### Success Response (200) - **scroll_x** (float) - The current horizontal scroll position. #### Response Example ```json { "scroll_x": 0.5 } ``` ## GET /item/{item_id}/scroll/x/max ### Description Gets the maximum horizontal scrollable position of a specified item. ### Method GET ### Endpoint /item/{item_id}/scroll/x/max ### Parameters #### Path Parameters - **item_id** (Union[int, str]) - Required - The ID or tag of the item to get the maximum scroll position for. ### Response #### Success Response (200) - **scroll_x_max** (float) - The maximum horizontal scroll position. #### Response Example ```json { "scroll_x_max": 1.0 } ``` ## GET /item/{item_id}/scroll/y ### Description Gets the current vertical scroll position of a specified item. ### Method GET ### Endpoint /item/{item_id}/scroll/y ### Parameters #### Path Parameters - **item_id** (Union[int, str]) - Required - The ID or tag of the item to get the scroll position for. ### Response #### Success Response (200) - **scroll_y** (float) - The current vertical scroll position. #### Response Example ```json { "scroll_y": 0.2 } ``` ## GET /item/{item_id}/scroll/y/max ### Description Gets the maximum vertical scrollable position of a specified item. ### Method GET ### Endpoint /item/{item_id}/scroll/y/max ### Parameters #### Path Parameters - **item_id** (Union[int, str]) - Required - The ID or tag of the item to get the maximum scroll position for. ### Response #### Success Response (200) - **scroll_y_max** (float) - The maximum vertical scroll position. #### Response Example ```json { "scroll_y_max": 1.0 } ``` ``` -------------------------------- ### Dear PyGui: Basic Window and Item Management Example Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/container-slots.rst This Python code demonstrates creating a Dear PyGui context, setting up a window, adding a button and a drawing line, and then printing the children and slot information for these items. It concludes with setting up and running the Dear PyGui viewport. ```python import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="about", width=400, height=400): dpg.add_button(label="Press me") dpg.draw_line((0, 10), (100, 100), color=(255, 0, 0, 255), thickness=1) # print children print(dpg.get_item_children(dpg.last_root())) # print children in slot 1 print(dpg.get_item_children(dpg.last_root(), 1)) # check draw_line's slot print(dpg.get_item_slot(dpg.last_item())) dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### draw_line Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Adds a line to the drawing canvas. Supports specifying start and end points, color, and thickness. ```APIDOC ## POST /draw_line ### Description Adds a line to the drawing canvas. Supports specifying start and end points, color, and thickness. ### Method POST ### Endpoint /draw_line ### Parameters #### Query Parameters - **p1** (List[float] | Tuple[float, ...]) - Required - Start of line. - **p2** (List[float] | Tuple[float, ...]) - Required - End of line. - **label** (str) - Optional - Overrides ‘name’ as label. - **user_data** (Any) - Optional - User data for callbacks - **use_internal_label** (bool) - Optional - Use generated internal label instead of user specified (appends ### uuid). - **tag** (int | str) - Optional - Unique id used to programmatically refer to the item.If label is unused this will be the label. - **parent** (int | str) - Optional - Parent to add this item to. (runtime adding) - **before** (int | str) - Optional - This item will be displayed before the specified item in the parent. - **show** (bool) - Optional - Attempt to render widget. - **color** (List[int] | Tuple[int, ...]) - Optional - - **thickness** (float) - Optional - - **id** (int | str) - Optional - (deprecated) ### Response #### Success Response (200) - **Return Value** (int | str) - The unique identifier for the created line. #### Response Example ```json { "return_value": 12345 } ``` ``` -------------------------------- ### Create Dear PyGui Window with Menu Bar using Context Managers (Python) Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/container-context-manager.rst Demonstrates creating a Dear PyGui window with a menu bar and nested menus using Python's context manager syntax. This approach simplifies parent-child relationships in the GUI. ```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() ``` -------------------------------- ### Apply Transform Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Applies a transformation matrix to a drawing node. This function is available starting from Dear PyGui version 1.1. ```APIDOC ## POST /dearpygui/apply_transform ### Description Applies a transformation matrix to a layer. New in 1.1. ### Method POST ### Endpoint /dearpygui/apply_transform ### Parameters #### Query Parameters - **item** (Union[int, str]) - Required - Drawing node to apply transform to. - **transform** (Any) - Required - Transformation matrix. ### Response #### Success Response (200) - **result** (None) - This function does not return a value. ``` -------------------------------- ### Get Item Width (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the width of a Dear PyGui item. This function is useful for responsive design or when precise layout control is needed. ```Python dearpygui.dearpygui.get_item_width(_item : Union[int, str]_) → Optional[int][source] Gets the item’s width. Returns width as a int or None ``` -------------------------------- ### Basic Staging and Presenting Items with Dear PyGui Source: https://dearpygui.readthedocs.io/en/latest/documentation/staging Demonstrates the fundamental usage of the Dear PyGui staging system. It shows how to create items within a stage and then move them to a parent window using `move_item`. This is useful for deferring item rendering. ```python import dearpygui.dearpygui as dpg dpg.create_context() def stage_items(): with dpg.stage(tag="stage1"): dpg.add_text("hello, i was added from a stage", tag="text_tag") def present_stage_items(): dpg.move_item("text_tag", parent="main_win") with dpg.window(label="Tutorial", tag="main_win"): dpg.add_button(label="stage items", callback=stage_items) dpg.add_button(label="present stages items", callback=present_stage_items) dpg.show_item_registry() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Get Viewport Configuration (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the configuration settings of a specific Dear PyGui viewport as a dictionary. This allows inspection of properties like position, size, and title. ```Python dearpygui.dearpygui.get_viewport_configuration(_item_)[source] Returns a viewport’s configuration. Parameters **item** (_Union_ _[__int_ _,__str_ _]_) – Returns dict ``` -------------------------------- ### dearpygui.dearpygui.configure_app Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Configures an item after creation. ```APIDOC ## dearpygui.dearpygui.configure_app ### Description Configures an item after creation. ### Method N/A (Function) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "No request body for this function." } ``` ### Response #### Success Response (200) None #### Response Example ```json { "example": "No response body." } ``` ``` -------------------------------- ### Get Platform Constant (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Returns an integer constant representing the current operating system platform. This function was introduced in version 1.6 and is useful for platform-specific logic. ```Python dearpygui.dearpygui.get_platform()[source] New in 1.6. Returns platform constant. Args: :returns: int ``` -------------------------------- ### Stage and Present Items with Dear PyGui Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/staging.rst Demonstrates the basic usage of the staging system in Dear PyGui. It shows how to create items within a stage and then present them to a window using `move_item`. This requires importing the `dearpygui.dearpygui` module. ```python import dearpygui.dearpygui as dpg dpg.create_context() def stage_items(): with dpg.stage(tag="stage1"): dpg.add_text("hello, i was added from a stage", tag="text_tag") def present_stage_items(): dpg.move_item("text_tag", parent="main_win") with dpg.window(label="Tutorial", tag="main_win"): dpg.add_button(label="stage items", callback=stage_items) dpg.add_button(label="present stages items", callback=present_stage_items) dpg.show_item_registry() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Get Dear PyGui Version (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the major and minor version numbers of the Dear PyGui library. This is important for compatibility checks and understanding feature availability. ```Python dearpygui.dearpygui.get_major_version()[source] return Dear PyGui Major Version dearpygui.dearpygui.get_minor_version()[source] return Dear PyGui Minor Version ``` -------------------------------- ### Manage Dear PyGui Container Stack for Window and Menu Bar (Python) Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/container-context-manager.rst Demonstrates manual management of Dear PyGui's container stack in Python to create a window and menu bar. This involves explicitly pushing and popping containers to define the widget hierarchy. ```python import dearpygui.dearpygui as dpg dpg.create_context() dpg.push_container_stack(dpg.add_window(label="Main")) dpg.push_container_stack(dpg.add_menu_bar()) dpg.push_container_stack(dpg.add_menu(label="Themes")) dpg.add_menu_item(label="Dark") dpg.add_menu_item(label="Light") dpg.pop_container_stack() dpg.push_container_stack(dpg.add_menu(label="Tools")) dpg.add_menu_item(label="Show Logger") dpg.add_menu_item(label="Show About") dpg.pop_container_stack() # remove menu_bar from container stack dpg.pop_container_stack() # remove window from container stack dpg.pop_container_stack() dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Get Mouse Drag Delta (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Returns the change in mouse position since the last mouse button event. This is useful for implementing drag-and-drop functionality or other mouse-driven interactions. ```Python dearpygui.dearpygui.get_mouse_drag_delta()[source] Returns mouse drag delta. Args: :returns: float ``` -------------------------------- ### Create DearPyGui Windows using Context Managers Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/item-creation.rst Demonstrates how to create two separate window items using DearPyGui's context manager functionality. This approach is recommended for organizing UI elements within containers. It initializes the DearPyGui context, creates the windows, sets up the viewport, and starts the application loop. ```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() ``` -------------------------------- ### Get All Item Types (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves a dictionary of all available item types within Dear PyGui. This is useful for introspection and understanding the full range of GUI components that can be created. ```Python dearpygui.dearpygui.get_item_types()[source] Returns an item types. Args: :returns: dict ``` -------------------------------- ### Create and Configure Dear PyGui Popups Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Creates a popup window in Dear PyGui. Popups are triggered by hovering over a parent item and clicking a specified mouse button. They can be configured as modal, with minimum and maximum sizes, and options to prevent movement or set a transparent background. ```python dearpygui.dearpygui.popup(_parent : Union[int, str]_, _mousebutton : int = 0_, _modal : bool = False_, _tag : Union[int, str] = 0_, _min_size : Union[List[int], Tuple[int, ...]] = [100, 100]_, _max_size : Union[List[int], Tuple[int, ...]] = [30000, 30000]_, _no_move : bool = False_, _no_background : bool = False_) → int[source] A window that will be displayed when a parent item is hovered and the corresponding mouse button has been clicked. By default a popup will shrink fit the items it contains. This is useful for context windows, and simple modal window popups. When popups are used a modal they have more avaliable settings (i.e. title, resize, width, height) These can be set by using configure item. This is a light wrapper over window. For more control over a modal|popup window use a normal window with the modal|popup keyword and set the item handler and mouse events manually. Parameters * **parent** – The UI item that will need to be hovered. * ****mousebutton** – The mouse button that will trigger the window to popup. * ****modal** – Will force the user to interact with the popup. * ****min_size** – New in 1.4. Minimum window size. * ****max_size** – New in 1.4. Maximum window size. * ****no_move** – New in 1.4. Prevents the window from moving based on user input. * ****no_background** – New in 1.4. Sets Background and border alpha to transparent. Returns item’s uuid ``` -------------------------------- ### Get Plot Mouse Position (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the current position of the mouse cursor specifically within the context of a plot widget. This allows for precise interaction with plot data points. ```Python dearpygui.dearpygui.get_plot_mouse_pos()[source] Returns mouse position in plot. Args: :returns: Union[List[int], Tuple[int, …]] ``` -------------------------------- ### Get Viewport Clear Color and Dimensions (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Retrieves the clear color (RGBA) of the Dear PyGui viewport and its client dimensions (width and height). These are fundamental properties for rendering and window management. ```Python dearpygui.dearpygui.get_viewport_clear_color() → List[int][source] Gets the viewport’s clear color. Returns List[int] dearpygui.dearpygui.get_viewport_client_height() → int[source] Gets the viewport’s client height. Returns viewport width dearpygui.dearpygui.get_viewport_client_width() → int[source] Gets the viewport’s client width. Returns viewport width ``` -------------------------------- ### Creating Smart Tables with Managed Columns in Dear PyGui Source: https://dearpygui.readthedocs.io/en/latest/extra/video-tutorials Provides an example of creating interactive smart tables using `managed_columns` in Dear PyGui. It demonstrates using basic widgets like `add_text`, `add_input_text`, and `add_input_float` within table cells and discusses refactoring into a `SmartTable` class. ```python import dearpygui.dearpygui as dpg class SmartTable: def __init__(self, parent, header, data): self.parent = parent self.header = header self.data = data self.table_tag = None def build(self): with dpg.table(header_row=True, resizable=True, policy=dpg.mvTable_SizingFixedFit, borders_innerH=True, borders_outerH=True, borders_innerV=True, borders_outerV=True, tag=self.table_tag, parent=self.parent) as self.table_tag: for col_name in self.header: dpg.add_table_column(label=col_name) for row_data in self.data: with dpg.table_row(): for i, item in enumerate(row_data): # Example: Use input widgets for editable cells if self.header[i] in ['Name', 'Value']: dpg.add_input_text(default_value=item, hint=self.header[i]) else: dpg.add_text(item) dpg.create_context() with dpg.window(label="Smart Table Tutorial") as main_window: table_header = ['ID', 'Name', 'Value', 'Status'] table_data = [ [1, 'Item A', '10.5', 'Active'], [2, 'Item B', '22.1', 'Inactive'], [3, 'Item C', '5.0', 'Active'] ] smart_table = SmartTable(main_window, table_header, table_data) smart_table.build() # Example of hiding a label dpg.add_input_text('##hidden_input', default_value='This label is hidden') # Example of using separator for spacing dpg.add_separator() dpg.add_button('Another Button') dpg.create_viewport(title='Dear PyGui Smart Tables', width=700, height=500) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Create Dear PyGui Window with Menu Bar using Aliases (Python) Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/container-context-manager.rst Illustrates building a Dear PyGui window with a menu bar by assigning parent-child relationships using string aliases (tags) in Python. This provides a readable way to manage widget relationships. ```python import dearpygui.dearpygui as dpg dpg.create_context() dpg.add_window(label="Main", tag="w") dpg.add_menu_bar(parent="w", tag="mb") dpg.add_menu(label="Themes", parent="mb", tag="themes") dpg.add_menu_item(label="Dark", parent="themes") dpg.add_menu_item(label="Light", parent="themes") dpg.add_menu(label="Other Themes", parent="themes", tag="other_themes") dpg.add_menu_item(label="Purple", parent="other_themes") dpg.add_menu_item(label="Gold", parent="other_themes") dpg.add_menu_item(label="Red", parent="other_themes") dpg.add_menu(label="Tools", parent="mb", tag="tools") dpg.add_menu_item(label="Show Logger", parent="tools") dpg.add_menu_item(label="Show About", parent="tools") dpg.add_menu(label="Oddities", parent="mb", tag="Oddities") dpg.add_button(label="A Button", parent="Oddities") dpg.add_simple_plot(label="A menu plot", default_value=(0.3, 0.9, 2.5, 8.9), height=80, parent="Oddities") dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ``` -------------------------------- ### Get Text Size (Dear PyGui) Source: https://dearpygui.readthedocs.io/en/latest/reference/dearpygui Calculates and returns the width and height of a given text string, considering a specified font and optional wrapping width. This function requires the GUI to have rendered at least once. ```Python dearpygui.dearpygui.get_text_size(_text_ , _** kwargs_)[source] Returns width/height of text with specified font (must occur after 1st frame). Parameters * **text** (_str_) – * **wrap_width** (_float_ _,__optional_) – Wrap width to use (-1.0 turns wrap off). * **font** (_Union_ _[__int_ _,__str_ _]__,__optional_) – Font to use. Returns Union[List[float], Tuple[float, …]] ``` -------------------------------- ### Directory Picker with Dear PyGui Source: https://dearpygui.readthedocs.io/en/latest/_sources/documentation/file-directory-selector.rst Demonstrates how to use the file dialog as a directory picker. It sets up callbacks for OK and Cancel actions and shows how to trigger the dialog from a button click. The dialog defaults to directories if no file extensions are specified. ```python import dearpygui.dearpygui as dpg dpg.create_context() def callback(sender, app_data): print('OK was clicked.') print("Sender: ", sender) print("App Data: ", app_data) def cancel_callback(sender, app_data): print('Cancel was clicked.') print("Sender: ", sender) print("App Data: ", app_data) dpg.add_file_dialog( directory_selector=True, show=False, callback=callback, tag="file_dialog_id", cancel_callback=cancel_callback, width=700 ,height=400) with dpg.window(label="Tutorial", width=800, height=300): dpg.add_button(label="Directory Selector", callback=lambda: dpg.show_item("file_dialog_id")) dpg.create_viewport(title='Custom Title', width=800, height=600) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() ```