Gtk.Stack¶
class — extends Widget, Accessible, Buildable, ConstraintTarget
Shows one of its children at a time.
<picture> <source srcset="stack-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkStack" src="stack.png"> </picture>
In contrast to GtkNotebook, GtkStack does not provide a means
for users to change the visible child. Instead, a separate widget
such as StackSwitcher or 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 Stack.set_transition_type.
These animations respect the Settings.gtk-enable-animations
setting.
GtkStack maintains a StackPage object for each added
child, which holds additional per-child properties. You
obtain the GtkStackPage for a child with Stack.get_page
and you can obtain a GtkSelectionModel containing all the pages
with Stack.get_pages.
GtkStack as GtkBuildable¶
To set child-specific properties in a .ui file, create GtkStackPage
objects explicitly, and set the child widget as a property on it:
<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 AccessibleRole.tab_panel role for the stack
pages, which are the accessible parent objects of the child widgets.
Constructors¶
new¶
Creates a new GtkStack.
Methods¶
add_child¶
Adds a child to stack.
Parameters:
child— the widget to add
add_named¶
Adds a child to stack.
The child is identified by the name.
Parameters:
child— the widget to addname— the name forchild
add_titled¶
Adds a child to stack.
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.
Parameters:
child— the widget to addname— the name forchildtitle— a human-readable title forchild
get_child_by_name¶
Finds the child with the name given as the argument.
Returns None if there is no child with this name.
Parameters:
name— the name of the child to find
get_hhomogeneous¶
Gets whether stack is horizontally homogeneous.
get_interpolate_size¶
Returns whether the GtkStack is set up to interpolate between
the sizes of children on page switch.
get_page¶
Returns the GtkStackPage object for child.
Parameters:
child— a child ofstack
get_pages¶
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 SelectionModel and can be used to track
and modify the visible page.
get_transition_duration¶
Returns the amount of time (in milliseconds) that
transitions between pages in stack will take.
get_transition_running¶
Returns whether the stack is currently in a transition from one page to
another.
get_transition_type¶
Gets the type of animation that will be used
for transitions between pages in stack.
get_vhomogeneous¶
Gets whether stack is vertically homogeneous.
get_visible_child¶
Gets the currently visible child of stack.
Returns None if there are no visible children.
get_visible_child_name¶
Returns the name of the currently visible child of stack.
Returns None if there is no visible child.
remove¶
Removes a child widget from stack.
Parameters:
child— the child to remove
set_hhomogeneous¶
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.
Parameters:
hhomogeneous—Trueto makestackhorizontally homogeneous
set_interpolate_size¶
Sets whether or not stack will interpolate its size when
changing the visible child.
If the Stack.interpolate-size property is set
to True, stack 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.
Parameters:
interpolate_size— the new value
set_transition_duration¶
Sets the duration that transitions between pages in stack
will take.
Parameters:
duration— the new duration, in milliseconds
set_transition_type¶
Sets the type of animation that will be used for
transitions between pages in stack.
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.
Parameters:
transition— the new transition type
set_vhomogeneous¶
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.
Parameters:
vhomogeneous—Trueto makestackvertically homogeneous
set_visible_child¶
Makes child the visible child of stack.
If child is different from the currently visible child,
the transition between the two will be animated with the
current transition type of stack.
Note that the child widget has to be visible itself
(see Widget.show) in order to become the visible
child of stack.
Parameters:
child— a child ofstack
set_visible_child_full¶
Makes the child with the given name visible.
Note that the child widget has to be visible itself
(see Widget.show) in order to become the visible
child of stack.
Parameters:
name— the name of the child to make visibletransition— the transition type to use
set_visible_child_name¶
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 stack.
Note that the child widget has to be visible itself
(see Widget.show) in order to become the visible
child of stack.
Parameters:
name— the name of the child to make visible
Properties¶
hhomogeneous¶
True if the stack allocates the same width for all children.
interpolate_size¶
Whether or not the size should smoothly change during the transition.
pages¶
A selection model with the stack pages.
transition_duration¶
The animation duration, in milliseconds.
transition_running¶
Whether or not the transition is currently running.
transition_type¶
The type of animation used to transition.
vhomogeneous¶
True if the stack allocates the same height for all children.
visible_child¶
The widget currently visible in the stack.
visible_child_name¶
The name of the widget currently visible in the stack.