Widget Objects¶
The wrapper object system used to provide an object-oriented API for DearPyGui.
Summary
This is the abstract base class for all GUI item wrapper objects. |
|
Mixin for widgets that use the DPG parent stack. |
|
Raised when a |
|
Mixin class for all widgets that can belong to containers. |
|
Fallback type for getting a widget that does not have a wrapper class. |
|
Descriptor used to get or set an item’s configuration. |
Widget¶
- class dearpygui_obj.wrapper.widget.Widget(*, id: Optional[int] = 0, callback: PyGuiCallback = None, **kwargs: Any)[source]¶
Bases:
abc.ABCThis is the abstract base class for all GUI item wrapper objects.
Keyword arguments passed to
__init__will be used to set the initial values of any config properties that belong to the class. Any left over keywords will be passed to the__setup_add_widget__()method to be given to DPG.You can find out what config properties there are using the
get_config_properties()method.It’s important that any subclasses can be instantiated with only the name_id argument being passed to
__init__. This allowsget_item_by_id()to work.- Parameters
name_id – optionally specify the unique widget ID.
callback – provide a callback that will be set with
set_callback().
ID and Existence
The unique name used by DearPyGui to reference this GUI item.
This property is
Falseif the GUI item has been deleted.Delete the item, this will invalidate the item and all its children.
Callbacks
A decorator that sets the item’s callback, and optionally, the callback data.
Get the callback used by DearPyGui.
Set the callback used by DearPyGui.
Get or set the callback data.
Other Properties and Status
Enable/disable rendering of the item.
Read or modify the ‘width’ config property.
Read or modify the ‘height’ config property.
The item’s current size as
(width, height).An item’s maximum allowable size as
(width, height).An item’s minimum allowable size as
(width, height).The content of the tooltip that is shown when the widget is hovered.
If not enabled, display greyed out text and disable interaction.
Checks if an item is visible on screen.
Checks if an item is hovered.
Checks if an item is focused.
- abstract __setup_add_widget__(dpg_args: MutableMapping[str, Any]) int[source]¶
This should create the widget using DearPyGui’s
add_*()functions and return the widget ID.
- __setup_preexisting__() None[source]¶
This can be overriden by subclasses to setup an object wrapper that has been created for a pre-existing GUI item.
Since we want to avoid duplicating state that already exists in DearPyGui, this method should rarely be needed.
- classmethod get_config_properties() Sequence[str][source]¶
Get the names of configuration properties as a list.
This can be useful to check which attributes are configuration properties and therefore can be given as keywords to
__init__.
- property id: int¶
The unique name used by DearPyGui to reference this GUI item.
- property is_valid: bool¶
This property is
Falseif the GUI item has been deleted.
- property callback_data: Any¶
Get or set the callback data.
- callback(_cb: PyGuiCallback = None, *, data: Optional[Any] = None) Callable[source]¶
A decorator that sets the item’s callback, and optionally, the callback data.
For example:
with Window('Example Window'): button = Button('Callback Button') # don't need callback data! @button.callback def callback(sender): ... # if data is a callable, it is invoked each time the callback fires # and the result is supplied to the callback. @button.callback(data='this could also be a callable') def callback(sender, data): ...
- tooltip: str¶
The content of the tooltip that is shown when the widget is hovered. To remove the tooltip, assign an empty string.
- property active: bool¶
Get whether the item is being interacted with.
- property max_size: Tuple[float, float]¶
An item’s maximum allowable size as
(width, height).
- property min_size: Tuple[float, float]¶
An item’s minimum allowable size as
(width, height).
- class dearpygui_obj.wrapper.widget.DefaultWidget(*, id: Optional[int] = 0, callback: PyGuiCallback = None, **kwargs: Any)[source]¶
Bases:
dearpygui_obj.wrapper.widget.Widget,dearpygui_obj.wrapper.widget.ItemWidgetMxFallback type for getting a widget that does not have a wrapper class.
When
get_item_by_id()is called to retrieve an item whose widget type does not have a wrapper object class associated with it, an instance of this type is created as a fallback.
ContainerWidgetMx¶
- class dearpygui_obj.wrapper.widget.ContainerWidgetMx(*args, **kwds)[source]¶
Bases:
abc.ABC,Generic[dearpygui_obj.wrapper.widget._TSelf]Mixin for widgets that use the DPG parent stack.
Typically when widgets are instantiated they are added to a container based on context. This behavior is a result of DPG’s parent stack and it makes it simple to create declarative-style GUIs.
After a container is used as a context manager, it is popped from DPG’s parent stack and cannot be re-added. Attempting to use it as a context manager for a second time will raise a
ContainerFinalizedError. This can also be checked using thefinalizedproperty.Once a container is finalized, additional children can still be added using the
add_child()method.- abstract property id: str¶
- property finalized: bool¶
Whether this container has already been used as a context manager.
- exception dearpygui_obj.wrapper.widget.ContainerFinalizedError[source]¶
Bases:
ExceptionRaised when a
ContainerWidgetMxis used after being finalized.
ItemWidgetMx¶
- class dearpygui_obj.wrapper.widget.ItemWidgetMx(*args, parent: str, before: str, **kwargs)[source]¶
Bases:
abc.ABCMixin class for all widgets that can belong to containers.
This mixin class is used to mark
Widgetsubtypes that can belong to a container (currently this includes all DPG widgets except forWindow). It provides its subtypes with methods to move widgets between different containers (re-parent) or within their own container.Typically when widgets are instantiated they are added to a container based on context. This behavior is a result of DPG’s parent stack and it makes it simple to create declarative-style GUIs.
If you need to add a new widget directly to a specific parent container, or just prefer a more OOP-style of specifying a widget’s parent, you can use the
add_to()andadd_before()constructor methods.- abstract property id: str¶
- set_parent(parent: ContainerWidget) None[source]¶
Re-parent the item, moving it.
Equivalent to calling
ContainerWidgetMx.add_child()on the parent.
- move_item_before(other: ItemWidget) None[source]¶
Attempt to place the item before another item, re-parenting it if necessary.
ValueWidgetMx¶
- class dearpygui_obj.wrapper.widget.ValueWidgetMx(*args, **kwds)[source]¶
Bases:
abc.ABC,Generic[dearpygui_obj.wrapper.widget._TValue]Mixin for all widgets that use the DPG value system.
The use of the
valueproperty depends on the specific kind of widget.ValueWidgets can be linked together or to a
DataValueby setting thedata_sourceconfig property.- abstract property id: str¶
- data_source: dearpygui_obj.DataValue[source]¶
Get or set the data source.
When retrieved, a
DataValuereferencing the data source will be produced.If a widget object or a
DataValueis assigned as the data source, this widget will become linked to the provided source. Otherwise, ifNoneis assigned, this widget will have its own value.
- property value: dearpygui_obj.wrapper.widget._TValue¶
Get or set the widget’s value.
ConfigProperty¶
- class dearpygui_obj.wrapper.widget.ConfigProperty(key: Optional[str] = None, *, no_init: bool = False, doc: str = '')[source]¶
Bases:
objectDescriptor used to get or set an item’s configuration.