Widget

class magicgui.widgets._bases.Widget(widget_type, name='', annotation=None, label=None, tooltip=None, visible=None, enabled=True, gui_only=False, parent=None, backend_kwargs={}, **extra)[source]

Bases: object

Basic Widget, wrapping a class that implements WidgetProtocol.

Parameters
  • widget_type (Type[WidgetProtocol]) – A class implementing a widget protocol. Will be instantiated during __init__.

  • name (str, optional) – The name of the parameter represented by this widget. by default “”

  • annotation (Any, optional) – The type annotation for the parameter represented by the widget, by default None

  • label (str) – A string to use for an associated Label widget (if this widget is being shown in a Container widget, and labels are on). By default, name will be used. Note: name refers the name of the parameter, as might be used in a signature, whereas label is just the label for that widget in the GUI.

  • tooltip (str, optional) – A tooltip to display when hovering over the widget.

  • visible (bool, optional) – Whether the widget is visible, by default True.

  • enabled (bool, optional) – Whether the widget is enabled, by default True.

  • gui_only (bool, optional) – If True, widget is excluded from any function signature representation. by default False. (This will likely be deprecated.)

  • parent (Widget, optional) – Optional parent widget of this widget. CAREFUL: if a parent is set, and subsequently deleted, this widget will likely be deleted as well (depending on the backend), and will no longer be usable.

  • backend_kwargs (dict, optional) – keyword argument to pass to the backend widget constructor.

Methods

close()

Close widget.

hide()

Hide widget.

render()

Return an RGBA (MxNx4) numpy array bitmap of the rendered widget.

show([run])

Show widget.

shown()

Context manager to show the widget.

Attributes

annotation

Return type annotation for the parameter represented by the widget.

enabled

Whether widget is enabled (editable).

height

Return the current height of the widget.

label

Return a label to use for this widget when present in Containers.

label_changed

Declares a signal emitter on a class.

max_height

Get the maximum height of the widget.

max_width

Get the maximum width of the widget.

min_height

Get the minimum height of the widget.

min_width

Get the minimum width of the widget.

native

Return native backend widget.

options

Return options currently being used in this widget.

param_kind

Return inspect.Parameter.kind represented by this widget.

parent

Return the parent widget.

parent_changed

Declares a signal emitter on a class.

root_native_widget

Return the root native backend widget.

tooltip

Get the tooltip for this widget.

visible

Return whether widget is visible.

widget_type

Return type of widget.

width

Return the current width of the widget.