Gtk.Stack

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 GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Buildable->Gtk.Widget Gtk.Container Gtk.Container Gtk.Stack Gtk.Stack Gtk.Container->Gtk.Stack Gtk.Widget->Gtk.Container

Example

../_images/Stack.png
Subclasses:

None

Methods

Inherited:

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

Structs:

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

class

new ()

add_named (child, name)

add_titled (child, name, title)

get_child_by_name (name)

get_hhomogeneous ()

get_homogeneous ()

get_interpolate_size ()

get_transition_duration ()

get_transition_running ()

get_transition_type ()

get_vhomogeneous ()

get_visible_child ()

get_visible_child_name ()

set_hhomogeneous (hhomogeneous)

set_homogeneous (homogeneous)

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.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10)

Properties

Inherited:

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

Name

Type

Flags

Short Description

hhomogeneous

bool

r/w/en

Horizontally homogeneous sizing

homogeneous

bool

r/w/en

Homogeneous sizing

interpolate-size

bool

r/w/en

Whether or not the size should smoothly change when changing between differently sized children

transition-duration

int

r/w/en

The animation duration, in milliseconds

transition-running

bool

r

Whether or not the transition is currently running

transition-type

Gtk.StackTransitionType

r/w/en

The type of animation used to transition

vhomogeneous

bool

r/w/en

Vertically homogeneous sizing

visible-child

Gtk.Widget

r/w/en

The widget currently visible in the stack

visible-child-name

str

r/w/en

The name of the widget currently visible in the stack

Child Properties

Name

Type

Default

Flags

Short Description

icon-name

str

None

r/w

The icon name of the child page

name

str

None

r/w

The name of the child page

needs-attention

bool

False

r/w

Whether this page needs attention

position

int

0

r/w

The index of the child in the parent

title

str

None

r/w

The title of the child page

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

parent_instance

Gtk.Container

r

Class Details

class Gtk.Stack(**kwargs)
Bases:

Gtk.Container

Abstract:

No

Structure:

Gtk.StackClass

The Gtk.Stack widget is a container which only shows one of its children at a time. In contrast to Gtk.Notebook, Gtk.Stack does not provide a means for users to change the visible child. Instead, the Gtk.StackSwitcher widget can be used with Gtk.Stack to provide this functionality.

Transitions between pages can be animated as slides or fades. This can be controlled with Gtk.Stack.set_transition_type(). These animations respect the Gtk.Settings :gtk-enable-animations setting.

The Gtk.Stack widget was added in GTK+ 3.10.

CSS nodes

Gtk.Stack has a single CSS node named stack.

classmethod new()[source]
Returns:

a new Gtk.Stack

Return type:

Gtk.Widget

Creates a new Gtk.Stack container.

New in version 3.10.

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

  • name (str) – the name for child

Adds a child to self. The child is identified by the name.

New in version 3.10.

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

  • name (str) – the name for child

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

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

New in version 3.10.

get_child_by_name(name)[source]
Parameters:

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

Returns:

the requested child of the Gtk.Stack

Return type:

Gtk.Widget or None

Finds the child of the Gtk.Stack with the name given as the argument. Returns None if there is no child with this name.

New in version 3.12.

get_hhomogeneous()[source]
Returns:

whether self is horizontally homogeneous.

Return type:

bool

Gets whether self is horizontally homogeneous. See Gtk.Stack.set_hhomogeneous().

New in version 3.16.

get_homogeneous()[source]
Returns:

whether self is homogeneous.

Return type:

bool

Gets whether self is homogeneous. See Gtk.Stack.set_homogeneous().

New in version 3.10.

get_interpolate_size()[source]
Returns:

True if child sizes are interpolated

Return type:

bool

Returns wether the Gtk.Stack is set up to interpolate between the sizes of children on page switch.

New in version 3.18.

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.

New in version 3.10.

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.

New in version 3.12.

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.

New in version 3.10.

get_vhomogeneous()[source]
Returns:

whether self is vertically homogeneous.

Return type:

bool

Gets whether self is vertically homogeneous. See Gtk.Stack.set_vhomogeneous().

New in version 3.16.

get_visible_child()[source]
Returns:

the visible child of the Gtk.Stack

Return type:

Gtk.Widget or None

Gets the currently visible child of self, or None if there are no visible children.

New in version 3.10.

get_visible_child_name()[source]
Returns:

the name of the visible child of the Gtk.Stack

Return type:

str or None

Returns the name of the currently visible child of self, or None if there is no visible child.

New in version 3.10.

set_hhomogeneous(hhomogeneous)[source]
Parameters:

hhomogeneous (bool) – True to make self horizontally homogeneous

Sets the Gtk.Stack to be horizontally homogeneous or not. If it is homogeneous, the Gtk.Stack will request the same width for all its children. If it isn’t, the stack may change width when a different child becomes visible.

New in version 3.16.

set_homogeneous(homogeneous)[source]
Parameters:

homogeneous (bool) – True to make self homogeneous

Sets the Gtk.Stack to be homogeneous or not. If it is homogeneous, the Gtk.Stack will request the same size for all its children. If it isn’t, the stack may change size when a different child becomes visible.

Since 3.16, homogeneity can be controlled separately for horizontal and vertical size, with the Gtk.Stack :hhomogeneous and Gtk.Stack :vhomogeneous.

New in version 3.10.

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 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.

New in version 3.18.

set_transition_duration(duration)[source]
Parameters:

duration (int) – the new duration, in milliseconds

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

New in version 3.10.

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.

New in version 3.10.

set_vhomogeneous(vhomogeneous)[source]
Parameters:

vhomogeneous (bool) – True to make self vertically homogeneous

Sets the Gtk.Stack to be vertically homogeneous or not. If it is homogeneous, the Gtk.Stack will request the same height for all its children. If it isn’t, the stack may change height when a different child becomes visible.

New in version 3.16.

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 Gtk.Widget.show()) in order to become the visible child of self.

New in version 3.10.

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 Gtk.Widget.show()) in order to become the visible child of self.

New in version 3.10.

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 Gtk.Widget.show()) in order to become the visible child of self.

New in version 3.10.

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.

New in version 3.16.

Gtk.Stack.props.homogeneous
Name:

homogeneous

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Homogeneous sizing

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 when changing between differently sized children

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.

New in version 3.16.

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