StackSidebar

The StackSidebar provides a way to switch between Stack objects via a list. The list is automatically populated with the children held by the Stack container.

Common use cases of the StackSidebar include preference screens, or other displays with many options which should be grouped together.

Constructor

The StackSidebar is constructed using:

stacksidebar = Gtk.StackSidebar()

Methods

To attach the Stack container to the StackSidebar, call:

stacksidebar.set_stack(stack)

The Stack associated with the StackSidebar can also be retrieved via:

stacksidebar.get_stack()

Property

The Stack object can also be handled by the properties:

stacksidebar.get_property("stack")
stacksidebar.set_property("stack", stack)

Example

Below is an example of an StackSidebar:

#!/usr/bin/env python3

from gi.repository import Gtk

class StackSidebar(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)

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

        stacksidebar = Gtk.StackSidebar()
        stacksidebar.set_stack(stack)
        grid.attach(stacksidebar, 0, 0, 1, 1)

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

window = StackSidebar()
window.show_all()

Gtk.main()

Download: StackSidebar