Gtk.Stack

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Stack Gtk.Stack Gtk.Widget->Gtk.Stack

Example

../_images/Stack.png
Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

add_child (child)

add_named (child, name)

add_titled (child, name, title)

get_child_by_name (name)

get_hhomogeneous ()

get_interpolate_size ()

get_page (child)

get_pages ()

get_transition_duration ()

get_transition_running ()

get_transition_type ()

get_vhomogeneous ()

get_visible_child ()

get_visible_child_name ()

remove (child)

set_hhomogeneous (hhomogeneous)

set_interpolate_size (interpolate_size)

set_transition_duration (duration)

set_transition_type (transition)

set_vhomogeneous (vhomogeneous)

set_visible_child (child)

set_visible_child_full (name, transition)

set_visible_child_name (name)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

hhomogeneous

bool

r/w/en

interpolate-size

bool

r/w/en

pages

Gtk.SelectionModel

r

transition-duration

int

r/w/en

transition-running

bool

r

transition-type

Gtk.StackTransitionType

r/w/en

vhomogeneous

bool

r/w/en

visible-child

Gtk.Widget

r/w/en

visible-child-name

str

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Gtk.Stack(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

GtkStack is a container which only shows one of its children at a time.

In contrast to GtkNotebook, GtkStack does not provide a means for users to change the visible child. Instead, a separate widget such as [class`Gtk`.StackSwitcher] or [class`Gtk`.StackSidebar] can be used with GtkStack to provide this functionality.

Transitions between pages can be animated as slides or fades. This can be controlled with [method`Gtk`.Stack.set_transition_type]. These animations respect the [property`Gtk`.Settings:gtk-enable-animations] setting.

GtkStack maintains a [class`Gtk`.StackPage] object for each added child, which holds additional per-child properties. You obtain the GtkStackPage for a child with [method`Gtk`.Stack.get_page] and you can obtain a GtkSelectionModel containing all the pages with [method`Gtk`.Stack.get_pages].

Gtk.Stack as Gtk.Buildable

To set child-specific properties in a .ui file, create GtkStackPage objects explicitly, and set the child widget as a property on it:

``xml
<object class=”GtkStack” id=”stack”>
<child>
<object class=”GtkStackPage”>

<property name=”name”>page1</property> <property name=”title”>In the beginning…</property> <property name=”child”>

<object class=”GtkLabel”>

<property name=”label”>It was dark</property>

</object>

</property>

</object>

</child>

``

CSS nodes

GtkStack has a single CSS node named stack.

Accessibility

GtkStack uses the Gtk.AccessibleRole.TAB_PANEL for the stack pages, which are the accessible parent objects of the child widgets.

classmethod new()[source]
Returns:

a new GtkStack

Return type:

Gtk.Widget

Creates a new GtkStack.

add_child(child)[source]
Parameters:

child (Gtk.Widget) – the widget to add

Returns:

the GtkStackPage for child

Return type:

Gtk.StackPage

Adds a child to self.

add_named(child, name)[source]
Parameters:
Returns:

the GtkStackPage for child

Return type:

Gtk.StackPage

Adds a child to self.

The child is identified by the name.

add_titled(child, name, title)[source]
Parameters:
  • child (Gtk.Widget) – the widget to add

  • name (str or None) – the name for child

  • title (str) – a human-readable title for child

Returns:

the GtkStackPage for child

Return type:

Gtk.StackPage

Adds a child to self.

The child is identified by the name. The title will be used by GtkStackSwitcher to represent child in a tab bar, so it should be short.

get_child_by_name(name)[source]
Parameters:

name (str) – the name of the child to find

Returns:

the requested child of the GtkStack

Return type:

Gtk.Widget or None

Finds the child with the name given as the argument.

Returns None if there is no child with this name.

get_hhomogeneous()[source]
Returns:

whether self is horizontally homogeneous.

Return type:

bool

Gets whether self is horizontally homogeneous.

get_interpolate_size()[source]
Returns:

True if child sizes are interpolated

Return type:

bool

Returns whether the GtkStack is set up to interpolate between the sizes of children on page switch.

get_page(child)[source]
Parameters:

child (Gtk.Widget) – a child of self

Returns:

the GtkStackPage for child

Return type:

Gtk.StackPage

Returns the GtkStackPage object for child.

get_pages()[source]
Returns:

a GtkSelectionModel for the stack’s children

Return type:

Gtk.SelectionModel

Returns a GListModel that contains the pages of the stack.

This can be used to keep an up-to-date view. The model also implements [iface`Gtk`.SelectionModel] and can be used to track and modify the visible page.

get_transition_duration()[source]
Returns:

the transition duration

Return type:

int

Returns the amount of time (in milliseconds) that transitions between pages in self will take.

get_transition_running()[source]
Returns:

True if the transition is currently running, False otherwise.

Return type:

bool

Returns whether the self is currently in a transition from one page to another.

get_transition_type()[source]
Returns:

the current transition type of self

Return type:

Gtk.StackTransitionType

Gets the type of animation that will be used for transitions between pages in self.

get_vhomogeneous()[source]
Returns:

whether self is vertically homogeneous.

Return type:

bool

Gets whether self is vertically homogeneous.

get_visible_child()[source]
Returns:

the visible child of the GtkStack

Return type:

Gtk.Widget or None

Gets the currently visible child of self.

Returns None if there are no visible children.

get_visible_child_name()[source]
Returns:

the name of the visible child of the GtkStack

Return type:

str or None

Returns the name of the currently visible child of self.

Returns None if there is no visible child.

remove(child)[source]
Parameters:

child (Gtk.Widget) – the child to remove

Removes a child widget from self.

set_hhomogeneous(hhomogeneous)[source]
Parameters:

hhomogeneous (bool) – True to make self horizontally homogeneous

Sets the GtkStack to be horizontally homogeneous or not.

If it is homogeneous, the GtkStack will request the same width for all its children. If it isn’t, the stack may change width when a different child becomes visible.

set_interpolate_size(interpolate_size)[source]
Parameters:

interpolate_size (bool) – the new value

Sets whether or not self will interpolate its size when changing the visible child.

If the [property`Gtk`.Stack:interpolate-size] property is set to True, self will interpolate its size between the current one and the one it’ll take after changing the visible child, according to the set transition duration.

set_transition_duration(duration)[source]
Parameters:

duration (int) – the new duration, in milliseconds

Sets the duration that transitions between pages in self will take.

set_transition_type(transition)[source]
Parameters:

transition (Gtk.StackTransitionType) – the new transition type

Sets the type of animation that will be used for transitions between pages in self.

Available types include various kinds of fades and slides.

The transition type can be changed without problems at runtime, so it is possible to change the animation based on the page that is about to become current.

set_vhomogeneous(vhomogeneous)[source]
Parameters:

vhomogeneous (bool) – True to make self vertically homogeneous

Sets the GtkStack to be vertically homogeneous or not.

If it is homogeneous, the GtkStack will request the same height for all its children. If it isn’t, the stack may change height when a different child becomes visible.

set_visible_child(child)[source]
Parameters:

child (Gtk.Widget) – a child of self

Makes child the visible child of self.

If child is different from the currently visible child, the transition between the two will be animated with the current transition type of self.

Note that the child widget has to be visible itself (see [method`Gtk`.Widget.show]) in order to become the visible child of self.

set_visible_child_full(name, transition)[source]
Parameters:

Makes the child with the given name visible.

Note that the child widget has to be visible itself (see [method`Gtk`.Widget.show]) in order to become the visible child of self.

set_visible_child_name(name)[source]
Parameters:

name (str) – the name of the child to make visible

Makes the child with the given name visible.

If child is different from the currently visible child, the transition between the two will be animated with the current transition type of self.

Note that the child widget has to be visible itself (see [method`Gtk`.Widget.show]) in order to become the visible child of self.

Property Details

Gtk.Stack.props.hhomogeneous
Name:

hhomogeneous

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

True if the stack allocates the same width for all children.

Gtk.Stack.props.interpolate_size
Name:

interpolate-size

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether or not the size should smoothly change during the transition.

Gtk.Stack.props.pages
Name:

pages

Type:

Gtk.SelectionModel

Default Value:

None

Flags:

READABLE

A selection model with the stack pages.

Gtk.Stack.props.transition_duration
Name:

transition-duration

Type:

int

Default Value:

200

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The animation duration, in milliseconds.

Gtk.Stack.props.transition_running
Name:

transition-running

Type:

bool

Default Value:

False

Flags:

READABLE

Whether or not the transition is currently running.

Gtk.Stack.props.transition_type
Name:

transition-type

Type:

Gtk.StackTransitionType

Default Value:

Gtk.StackTransitionType.NONE

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The type of animation used to transition.

Gtk.Stack.props.vhomogeneous
Name:

vhomogeneous

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

True if the stack allocates the same height for all children.

Gtk.Stack.props.visible_child
Name:

visible-child

Type:

Gtk.Widget

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The widget currently visible in the stack.

Gtk.Stack.props.visible_child_name
Name:

visible-child-name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The name of the widget currently visible in the stack.