Gtk.Box


Gtk.Box — A container box

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Box
                    ├── Gtk.AppChooserWidget
                    ├── Gtk.ButtonBox
                    ├── Gtk.ColorChooserWidget
                    ├── Gtk.ColorSelection
                    ├── Gtk.FileChooserButton
                    ├── Gtk.FileChooserWidget
                    ├── Gtk.FontChooserWidget
                    ├── Gtk.FontSelection
                    ├── Gtk.HBox
                    ├── Gtk.InfoBar
                    ├── Gtk.RecentChooserWidget
                    ├── Gtk.StackSwitcher
                    ├── Gtk.Statusbar
                    ╰── Gtk.VBox

Functions:

Description:

The Gtk.Box widget organizes child widgets into a rectangular area.

The rectangular area of a Gtk.Box is organized into either a single row or a single column of child widgets depending upon the orientation.

Thus, all children of a Gtk.Box are allocated one dimension in common, which is the height of a row, or the width of a column.

Gtk.Box uses a notion of packing. Packing refers to adding widgets with reference to a particular position in a Gtk.Container. For a GtkBox, 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 aGtk.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 GtkBox 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.

Note that a single-row or single-column Gtk.Grid provides exactly the same functionality as Gtk.Box.


Function Details:

new()

new (orientation:Gtk.Orientation, spacing:int) -> Gtk.Widget

Creates a new Gtk.Box.

  • Returns: a new Gtk.Box.

  • Since: 3.0


pack_start()

pack_start (self, child:Gtk.Widget, expand:bool, fill:bool, padding:int)

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


pack_end()

pack_end (self, child:Gtk.Widget, expand:bool, fill:bool, padding:int)

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


get_homogeneous()

get_homogeneous (self) -> bool

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

  • Returns: True if the box is homogeneous.

set_homogeneous()

set_homogeneous (self, homogeneous:bool)

Sets the “homogeneous” property of box, controllingwhether or not all children of box are given equal spacein the box.


get_spacing()

get_spacing (self) -> int

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

  • Returns: spacing between children

set_spacing()

set_spacing (self, spacing:int)

Sets the “spacing” property of box, which is thenumber of pixels to place between children of box.


reorder_child()

reorder_child (self, child:Gtk.Widget, position:int)

Moves child to a new position in the list of box children.The list contains widgets packed GTK_PACK_STARTas well as widgets packed GTK_PACK_END, in the order that thesewidgets were added to box. A widget’s position in the box children list determines wherethe widget is packed into box. A child widget at some positionin the list will be packed just after all other widgets of thesame packing type that appear earlier in the list.


query_child_packing()

query_child_packing (self, child:Gtk.Widget) -> expand:bool, fill:bool, padding:int, pack_type:Gtk.PackType

Obtains information about how child is packed into box.


set_child_packing()

set_child_packing (self, child:Gtk.Widget, expand:bool, fill:bool, padding:int, pack_type:Gtk.PackType)

Sets the way child is packed into box.


get_baseline_position()

get_baseline_position (self) -> Gtk.BaselinePosition

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

  • Returns: the baseline position

  • Since: 3.10


set_baseline_position()

set_baseline_position (self, position:Gtk.BaselinePosition)

Sets the baseline position of a box. This affectsonly horizontal boxes with at least one baseline alignedchild. If there is more vertical space available than requested,and the baseline is not allocated by the parent thenposition is used to allocate the baseline wrt theextra space available.

  • Since: 3.10

get_center_widget()

get_center_widget (self) -> Gtk.Widget

Retrieves the center widget of the box.

  • Returns: the center widget.

  • Since: 3.12


set_center_widget()

set_center_widget (self, widget:Gtk.Widget=None)

Sets a center widget; that is a child widget that will becentered with respect to the full width of the box, evenif the children at either side take up different amountsof space.

  • Since: 3.12

Example:

#/usr/bin/env python3

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class Box(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title("Box")
        self.set_default_size(200, 200)
        self.connect("destroy", Gtk.main_quit)

        hbox = Gtk.Box()
        hbox.set_orientation(Gtk.Orientation.HORIZONTAL)
        hbox.set_spacing(5)
        self.add(hbox)

        label = Gtk.Label(label="Label 1")
        hbox.pack_start(label, True, True, 0)
        label = Gtk.Label(label="Label 2")
        hbox.pack_start(label, True, True, 0)

        vbox = Gtk.Box()
        vbox.set_orientation(Gtk.Orientation.VERTICAL)
        vbox.set_spacing(5)
        hbox.add(vbox)

        label = Gtk.Label(label="Label 3")
        vbox.pack_start(label, True, True, 0)
        label = Gtk.Label(label="Label 4")
        vbox.pack_start(label, True, True, 0)

window = Box()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""