Gtk.Box

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.Orientable Gtk.Orientable GObject.GInterface->Gtk.Orientable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Box Gtk.Box Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Container->Gtk.Box Gtk.Orientable->Gtk.Box Gtk.Widget->Gtk.Container

Subclasses:

Gtk.AppChooserWidget, Gtk.ButtonBox, Gtk.ColorChooserWidget, Gtk.ColorSelection, Gtk.FileChooserButton, Gtk.FileChooserWidget, Gtk.FontChooserWidget, Gtk.FontSelection, Gtk.HBox, Gtk.InfoBar, Gtk.RecentChooserWidget, Gtk.ShortcutLabel, Gtk.ShortcutsGroup, Gtk.ShortcutsSection, Gtk.ShortcutsShortcut, Gtk.StackSwitcher, Gtk.Statusbar, Gtk.VBox

Methods

Inherited:

Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Orientable (2)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new (orientation, spacing)

get_baseline_position ()

get_center_widget ()

get_homogeneous ()

get_spacing ()

pack_end (child, expand, fill, padding)

pack_start (child, expand, fill, padding)

query_child_packing (child)

reorder_child (child, position)

set_baseline_position (position)

set_center_widget (widget)

set_child_packing (child, expand, fill, padding, pack_type)

set_homogeneous (homogeneous)

set_spacing (spacing)

Virtual Methods

Inherited:

Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

Properties

Inherited:

Gtk.Container (3), Gtk.Widget (39), Gtk.Orientable (1)

Name

Type

Flags

Short Description

baseline-position

Gtk.BaselinePosition

r/w/en

The position of the baseline aligned widgets if extra space is available

homogeneous

bool

r/w/en

Whether the children should all be the same size

spacing

int

r/w/en

The amount of space between children

Child Properties

Name

Type

Default

Flags

Short Description

expand

bool

False

r/w

Whether the child should receive extra space when the parent grows

fill

bool

True

r/w

Whether extra space given to the child should be allocated to the child or used as padding

pack-type

Gtk.PackType

Gtk.PackType.START

r/w

A Gtk.PackType indicating whether the child is packed with reference to the start or end of the parent

padding

int

0

r/w

Extra space to put between the child and its neighbors, in pixels

position

int

0

r/w

The index of the child in the parent

Style Properties

Inherited:

Gtk.Widget (17)

Signals

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Fields

Inherited:

Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Name

Type

Access

Description

container

Gtk.Container

r

Class Details

class Gtk.Box(*args, **kwargs)
Bases:

Gtk.Container, Gtk.Orientable

Abstract:

No

Structure:

Gtk.BoxClass

The Gtk.Box widget arranges child widgets into a single row or column, depending upon the value of its Gtk.Orientable :orientation property. Within the other dimension, all children are allocated the same size. Of course, the Gtk.Widget :halign and Gtk.Widget :valign properties can be used on the children to influence their allocation.

Gtk.Box uses a notion of packing. Packing refers to adding widgets with reference to a particular position in a Gtk.Container. For a Gtk.Box, there are two reference positions: the start and the end of the box. For a vertical Gtk.Box, the start is defined as the top of the box and the end is defined as the bottom. For a horizontal Gtk.Box the start is defined as the left side and the end is defined as the right side.

Use repeated calls to Gtk.Box.pack_start() to pack widgets into a Gtk.Box from start to end. Use Gtk.Box.pack_end() to add widgets from end to start. You may intersperse these calls and add widgets from both ends of the same Gtk.Box.

Because Gtk.Box is a Gtk.Container, you may also use Gtk.Container.add() to insert widgets into the box, and they will be packed with the default values for expand and fill child properties. Use Gtk.Container.remove() to remove widgets from the Gtk.Box.

Use Gtk.Box.set_homogeneous() to specify whether or not all children of the Gtk.Box are forced to get the same amount of space.

Use Gtk.Box.set_spacing() to determine how much space will be minimally placed between all children in the Gtk.Box. Note that spacing is added between the children, while padding added by Gtk.Box.pack_start() or Gtk.Box.pack_end() is added on either side of the widget it belongs to.

Use Gtk.Box.reorder_child() to move a Gtk.Box child to a different place in the box.

Use Gtk.Box.set_child_packing() to reset the expand, fill and padding child properties. Use Gtk.Box.query_child_packing() to query these fields.

CSS nodes

Gtk.Box uses a single CSS node with name box.

In horizontal orientation, the nodes of the children are always arranged from left to right. So :first-child will always select the leftmost child, regardless of text direction.

classmethod new(orientation, spacing)[source]
Parameters:
  • orientation (Gtk.Orientation) – the box’s orientation.

  • spacing (int) – the number of pixels to place by default between children.

Returns:

a new Gtk.Box.

Return type:

Gtk.Widget

Creates a new Gtk.Box.

New in version 3.0.

get_baseline_position()[source]
Returns:

the baseline position

Return type:

Gtk.BaselinePosition

Gets the value set by Gtk.Box.set_baseline_position().

New in version 3.10.

get_center_widget()[source]
Returns:

the center widget or None in case no center widget is set.

Return type:

Gtk.Widget or None

Retrieves the center widget of the box.

New in version 3.12.

get_homogeneous()[source]
Returns:

True if the box is homogeneous.

Return type:

bool

Returns whether the box is homogeneous (all children are the same size). See Gtk.Box.set_homogeneous().

get_spacing()[source]
Returns:

spacing between children

Return type:

int

Gets the value set by Gtk.Box.set_spacing().

pack_end(child, expand, fill, padding)[source]
Parameters:
  • child (Gtk.Widget) – the Gtk.Widget to be added to self

  • expand (bool) – True if the new child is to be given extra space allocated to self. The extra space will be divided evenly between all children of self that use this option

  • fill (bool) – True if space given to child by the expand option is actually allocated to child, rather than just padding it. This parameter has no effect if expand is set to False. A child is always allocated the full height of a horizontal Gtk.Box and the full width of a vertical Gtk.Box. This option affects the other dimension

  • padding (int) – extra space in pixels to put between this child and its neighbors, over and above the global amount specified by Gtk.Box :spacing property. If child is a widget at one of the reference ends of self, then padding pixels are also put between child and the reference edge of self

Adds child to self, packed with reference to the end of self. The child is packed after (away from end of) any other child packed with reference to the end of self.

pack_start(child, expand, fill, padding)[source]
Parameters:
  • child (Gtk.Widget) – the Gtk.Widget to be added to self

  • expand (bool) – True if the new child is to be given extra space allocated to self. The extra space will be divided evenly between all children that use this option

  • fill (bool) – True if space given to child by the expand option is actually allocated to child, rather than just padding it. This parameter has no effect if expand is set to False. A child is always allocated the full height of a horizontal Gtk.Box and the full width of a vertical Gtk.Box. This option affects the other dimension

  • padding (int) – extra space in pixels to put between this child and its neighbors, over and above the global amount specified by Gtk.Box :spacing property. If child is a widget at one of the reference ends of self, then padding pixels are also put between child and the reference edge of self

Adds child to self, packed with reference to the start of self. The child is packed after any other child packed with reference to the start of self.

query_child_packing(child)[source]
Parameters:

child (Gtk.Widget) – the Gtk.Widget of the child to query

Returns:

expand:

pointer to return location for expand child property

fill:

pointer to return location for fill child property

padding:

pointer to return location for padding child property

pack_type:

pointer to return location for pack-type child property

Return type:

(expand: bool, fill: bool, padding: int, pack_type: Gtk.PackType)

Obtains information about how child is packed into self.

reorder_child(child, position)[source]
Parameters:
  • child (Gtk.Widget) – the Gtk.Widget to move

  • position (int) – the new position for child in the list of children of self, starting from 0. If negative, indicates the end of the list

Moves child to a new position in the list of self children. The list contains widgets packed Gtk.PackType.START as well as widgets packed Gtk.PackType.END, in the order that these widgets were added to self.

A widget’s position in the self children list determines where the widget is packed into self. A child widget at some position in the list will be packed just after all other widgets of the same packing type that appear earlier in the list.

set_baseline_position(position)[source]
Parameters:

position (Gtk.BaselinePosition) – a Gtk.BaselinePosition

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 wrt the extra space available.

New in version 3.10.

set_center_widget(widget)[source]
Parameters:

widget (Gtk.Widget or None) – the widget to center

Sets a center widget; that is a child widget that will be centered with respect to the full width of the box, even if the children at either side take up different amounts of space.

New in version 3.12.

set_child_packing(child, expand, fill, padding, pack_type)[source]
Parameters:
  • child (Gtk.Widget) – the Gtk.Widget of the child to set

  • expand (bool) – the new value of the expand child property

  • fill (bool) – the new value of the fill child property

  • padding (int) – the new value of the padding child property

  • pack_type (Gtk.PackType) – the new value of the pack-type child property

Sets the way child is packed into self.

set_homogeneous(homogeneous)[source]
Parameters:

homogeneous (bool) – a boolean value, True to create equal allotments, False for variable allotments

Sets the Gtk.Box :homogeneous property of self, controlling whether or not all children of self are given equal space in the box.

set_spacing(spacing)[source]
Parameters:

spacing (int) – the number of pixels to put between children

Sets the Gtk.Box :spacing property of self, which is the number of pixels to place between children of self.

Property Details

Gtk.Box.props.baseline_position
Name:

baseline-position

Type:

Gtk.BaselinePosition

Default Value:

Gtk.BaselinePosition.CENTER

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The position of the baseline aligned widgets if extra space is available

Gtk.Box.props.homogeneous
Name:

homogeneous

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the children should all be the same size

Gtk.Box.props.spacing
Name:

spacing

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The amount of space between children