DearPyGui: Cannot get size of node editor nodes with e.g. dpg.get_item_width

Version of Dear PyGui

Version: 0.8.64 on Python 3.7 Operating System: Scientific Linux 7.4

My Issue/Question

When using the node editor, nodes set their shape based on their child items. I want to be able to poll what the shape is, which will allow me to start positioning nodes sensibly when they are programmatically created.

Generally speaking, you can use dpg.get_item_pos, dpg.get_item_width/dpg.get_item_height and dpg.get_item_rect_min/dpg.get_item_rect_max to get this sort of information about any DearPyGui item.

However, for nodes, the width and height always return zero and the rect min and max are always equal. (They are also different from dpg.get_item_pos and I don’t know if that is a bug or a feature based on the rect covering different elements than the pos…)

To Reproduce

Run the example below. Press the button in the window and observe the unhelpful values returned by the various relevant calls for properties of the node.

Expected behavior

I would expect dpg.get_item_pos and dpg.get_item_rect_min to return the pixel position of the top right of the node in the node editor coordinates, dpg.get_item_width and dpg.get_item_height to give the pixel width and height of the node and dpg.get_item_rect_max to equal dpg.get_item_rect_min + (dpg.get_item_width, dpg.get_item_height).

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

with dpg.window() as window_id:

    dpg.set_primary_window(window_id, True)

    # Add a node editor with the simplest non-empty node
    with dpg.node_editor() as node_editor:
        with dpg.node(label="What width??") as node:
            with dpg.node_attribute():
                dpg.add_text(default_value="Empty attribute")

    # Add a function to print properties of the node
    def callback():
        print("Position (works):", dpg.get_item_pos(node))
        print("Width (broken):", dpg.get_item_width(node))
        print("Height (broken):", dpg.get_item_height(node))
        print("Rect min (has value):", dpg.get_item_rect_min(node))
        print("Rect max (has value but shouldn't equal rect min):", dpg.get_item_rect_max(node))
        print()

    # Add a button in a window to call that function
    with dpg.window():
        dpg.add_button(label="check width", callback=callback)

dpg.start_dearpygui()

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 16 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Same problem here. When I want to get the window’s width it will return 0.

Doesent seem to work for me. Running DPG 1.8.0 on python 3.9.5. dpg.get_item_width, dpg.get_item_height, dpg.get_item_rect_min, dpg.get_item_rect_max, dpg.get_item_rect_size all still return 0 for me

Edit: When running in debug mode it sometimes works. No idea why