Gtk.Stack


Gtk.Stack — A stacking container

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Stack

See also:

Gtk.Notebook, Gtk.StackSwitcher


Functions:

Description:

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.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.Stack container.

  • Returns: a new Gtk.Stack

  • Since: 3.10


add_named()

add_named (self, child:Gtk.Widget, name:str)

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

  • Since: 3.10

add_titled()

add_titled (self, child:Gtk.Widget, name:str, title:str)

Adds a child to stack.The child is identified by the name. The titlewill be used by Gtk.StackSwitcher to representchild in a tab bar, so it should be short.

  • Since: 3.10

get_child_by_name()

get_child_by_name (self, name:str) -> Gtk.Widget

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

  • Returns: the requested child of the Gtk.Stack.

  • Since: 3.12


set_visible_child()

set_visible_child (self, child:Gtk.Widget)

Makes child the visible child of stack. If child is different from the currentlyvisible child, the transition between thetwo will be animated with the currenttransition type of stack. Note that the child widget has to be visible itself(see `Gtk.Widget:show()) in order to become the visiblechild ofstack`.

  • Since: 3.10

get_visible_child()

get_visible_child (self) -> Gtk.Widget

Gets the currently visible child of stack, or None ifthere are no visible children.

  • Returns: the visible child of the Gtk.Stack.

  • Since: 3.10


set_visible_child_name()

set_visible_child_name (self, name:str)

Makes the child with the given name visible. If child is different from the currentlyvisible child, the transition between thetwo will be animated with the currenttransition type of stack. Note that the child widget has to be visible itself(see `Gtk.Widget:show()) in order to become the visiblechild ofstack`.

  • Since: 3.10

get_visible_child_name()

get_visible_child_name (self) -> str

Returns the name of the currently visible child of stack, orNone if there is no visible child.

  • Returns: the name of the visible child of the Gtk.Stack.

  • Since: 3.10


set_visible_child_full()

set_visible_child_full (self, name:str, transition:Gtk.StackTransitionType)

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 visiblechild ofstack`.

  • Since: 3.10

set_homogeneous()

set_homogeneous (self, homogeneous:bool)

Sets the Gtk.Stack to be homogeneous or not. If itis homogeneous, the Gtk.Stack will request the samesize for all its children. If it isn't, the stackmay change size when a different child becomes visible. Since 3.16, homogeneity can be controlled separatelyfor horizontal and vertical size, with the“hhomogeneous” and “vhomogeneous”.

  • Since: 3.10

get_homogeneous()

get_homogeneous (self) -> bool

Gets whether stack is homogeneous.See Gtk.Stack:set_homogeneous().

  • Returns: whether stackis homogeneous.

  • Since: 3.10


set_hhomogeneous()

set_hhomogeneous (self, hhomogeneous:bool)

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

  • Since: 3.16

get_hhomogeneous()

get_hhomogeneous (self) -> bool

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

  • Returns: whether stackis horizontally homogeneous.

  • Since: 3.16


set_vhomogeneous()

set_vhomogeneous (self, vhomogeneous:bool)

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

  • Since: 3.16

get_vhomogeneous()

get_vhomogeneous (self) -> bool

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

  • Returns: whether stackis vertically homogeneous.

  • Since: 3.16


set_transition_duration()

set_transition_duration (self, duration:int)

Sets the duration that transitions between pages in stackwill take.

  • Since: 3.10

get_transition_duration()

get_transition_duration (self) -> int

Returns the amount of time (in milliseconds) thattransitions between pages in stack will take.

  • Returns: the transition duration

  • Since: 3.10


set_transition_type()

set_transition_type (self, transition:Gtk.StackTransitionType)

Sets the type of animation that will be used fortransitions between pages in stack. Availabletypes include various kinds of fades and slides. The transition type can be changed without problemsat runtime, so it is possible to change the animationbased on the page that is about to become current.

  • Since: 3.10

get_transition_type()

get_transition_type (self) -> Gtk.StackTransitionType

Gets the type of animation that will be usedfor transitions between pages in stack.

  • Returns: the current transition type of stack

  • Since: 3.10


get_transition_running()

get_transition_running (self) -> bool

Returns whether the stack is currently in a transition from one page toanother.

  • Returns: True if the transition is currently running, FALSE otherwise.

  • Since: 3.12


get_interpolate_size()

get_interpolate_size (self) -> bool
  • Returns: True If the Gtk.Stack is set up to interpolate betweenvisible-child sizes, FALSE otherwise.

  • Since: 3.18


set_interpolate_size()

set_interpolate_size (self, interpolate_size:bool)

Sets whether or not stack will interpolate its size whenchanging the visible child. If the interpolate-size propertyis set to True, stack will interpolate its size betweenthe current one and the one it'll take after changing the visible-child,according to the set transition-duration.

  • Since: 3.18

Example:

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

class Stack(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(400, 300)
        self.connect("destroy", Gtk.main_quit)

        grid = Gtk.Grid()
        self.add(grid)

        self.stack = Gtk.Stack()
        self.stack.set_vexpand(True)
        self.stack.set_hexpand(True)
        grid.attach(self.stack, 0, 0, 1, 1)

        buttonbox = Gtk.ButtonBox()
        buttonbox.set_layout(Gtk.ButtonBoxStyle.CENTER)
        grid.attach(buttonbox, 0, 1, 1, 1)

        for page in range(1, 4):
            label = Gtk.Label("Stack Content on Page %i" % (page))
            name = "label%i" % page
            self.stack.add_named(label, name)

            button = Gtk.Button("Page %i" % (page))
            button.connect("clicked", self.on_button_clicked, page)
            buttonbox.add(button)

    def on_button_clicked(self, button, page):
        name = "label%i" % page
        self.stack.set_visible_child_name(name)

window = Stack()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""