:right-sidebar: True Box =================================================================== .. currentmodule:: gi.repository.Gtk .. class:: Box(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gtk.Widget`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gtk.ShortcutsGroup`, :class:`~gi.repository.Gtk.ShortcutsSection` Implemented Interfaces: :class:`~gi.repository.Gtk.Accessible`, :class:`~gi.repository.Gtk.Buildable`, :class:`~gi.repository.Gtk.ConstraintTarget`, :class:`~gi.repository.Gtk.Orientable` The ``GtkBox`` widget arranges child widgets into a single row or column. .. image:: https://docs.gtk.org/gtk4/box.png Whether it is a row or column depends on the value of its :obj:`~gi.repository.Gtk.Orientable.props.orientation` property. Within the other dimension, all children are allocated the same size. Of course, the :obj:`~gi.repository.Gtk.Widget.props.halign` and :obj:`~gi.repository.Gtk.Widget.props.valign` properties can be used on the children to influence their allocation. Use repeated calls to :obj:`~gi.repository.Gtk.Box.append` to pack widgets into a ``GtkBox`` from start to end. Use :obj:`~gi.repository.Gtk.Box.remove` to remove widgets from the ``GtkBox``. :obj:`~gi.repository.Gtk.Box.insert_child_after` can be used to add a child at a particular position. Use :obj:`~gi.repository.Gtk.Box.set_homogeneous` to specify whether or not all children of the ``GtkBox`` are forced to get the same amount of space. Use :obj:`~gi.repository.Gtk.Box.set_spacing` to determine how much space will be minimally placed between all children in the ``GtkBox``. Note that spacing is added *between* the children. Use :obj:`~gi.repository.Gtk.Box.reorder_child_after` to move a child to a different place in the box. CSS nodes --------- ``GtkBox`` uses a single CSS node with name box. Accessibility ------------- Until GTK 4.10, ``GtkBox`` used the ``GTK_ACCESSIBLE_ROLE_GROUP`` role. Starting from GTK 4.12, ``GtkBox`` uses the ``GTK_ACCESSIBLE_ROLE_GENERIC`` role. Constructors ------------ .. rst-class:: interim-class .. class:: Box :no-index: .. classmethod:: new(orientation: ~gi.repository.Gtk.Orientation, spacing: int) -> ~gi.repository.Gtk.Widget Creates a new ``GtkBox``. :param orientation: the box’s orientation :param spacing: the number of pixels to place by default between children Methods ------- .. rst-class:: interim-class .. class:: Box :no-index: .. method:: append(child: ~gi.repository.Gtk.Widget) -> None Adds ``child`` as the last child to ``box``. :param child: the ``GtkWidget`` to append .. method:: get_baseline_child() -> int Gets the value set by :func:`~gi.repository.Gtk.Box.set_baseline_child`. .. versionadded:: 4.12 .. method:: get_baseline_position() -> ~gi.repository.Gtk.BaselinePosition Gets the value set by :func:`~gi.repository.Gtk.Box.set_baseline_position`. .. method:: get_homogeneous() -> bool Returns whether the box is homogeneous (all children are the same size). .. method:: get_spacing() -> int Gets the value set by :func:`~gi.repository.Gtk.Box.set_spacing`. .. method:: insert_child_after(child: ~gi.repository.Gtk.Widget, sibling: ~gi.repository.Gtk.Widget | None = None) -> None Inserts ``child`` in the position after ``sibling`` in the list of ``box`` children. If ``sibling`` is :const:`None`, insert ``child`` at the first position. :param child: the ``GtkWidget`` to insert :param sibling: the sibling after which to insert ``child`` .. method:: prepend(child: ~gi.repository.Gtk.Widget) -> None Adds ``child`` as the first child to ``box``. :param child: the ``GtkWidget`` to prepend .. method:: remove(child: ~gi.repository.Gtk.Widget) -> None Removes a child widget from ``box``. The child must have been added before with :obj:`~gi.repository.Gtk.Box.append`, :obj:`~gi.repository.Gtk.Box.prepend`, or :obj:`~gi.repository.Gtk.Box.insert_child_after`. :param child: the child to remove .. method:: reorder_child_after(child: ~gi.repository.Gtk.Widget, sibling: ~gi.repository.Gtk.Widget | None = None) -> None Moves ``child`` to the position after ``sibling`` in the list of ``box`` children. If ``sibling`` is :const:`None`, move ``child`` to the first position. :param child: the ``GtkWidget`` to move, must be a child of ``box`` :param sibling: the sibling to move ``child`` after .. method:: set_baseline_child(child: int) -> None Sets the baseline child of a box. This affects only vertical boxes. .. versionadded:: 4.12 :param child: a child, or -1 .. method:: set_baseline_position(position: ~gi.repository.Gtk.BaselinePosition) -> None Sets the baseline position of a box. This affects only horizontal boxes with at least one baseline aligned child. If there is more vertical space available than requested, and the baseline is not allocated by the parent then ``position`` is used to allocate the baseline with respect to the extra space available. :param position: a ``GtkBaselinePosition`` .. method:: set_homogeneous(homogeneous: bool) -> None Sets whether or not all children of ``box`` are given equal space in the box. :param homogeneous: a boolean value, :const:`True` to create equal allotments, :const:`False` for variable allotments .. method:: set_spacing(spacing: int) -> None Sets the number of pixels to place between children of ``box``. :param spacing: the number of pixels to put between children Properties ---------- .. rst-class:: interim-class .. class:: Box :no-index: .. attribute:: props.baseline_child :type: int The child that determines the baseline, in vertical orientation. .. versionadded:: 4.12 .. attribute:: props.baseline_position :type: ~gi.repository.Gtk.BaselinePosition The position of the baseline aligned widgets if extra space is available. .. attribute:: props.homogeneous :type: bool Whether the children should all be the same size. .. attribute:: props.spacing :type: int The amount of space between children. Fields ------ .. rst-class:: interim-class .. class:: Box :no-index: .. attribute:: parent_instance