Gtk.StackSwitcher


Gtk.StackSwitcher — A controller for Gtk.Stack

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Box
                    ╰── Gtk.StackSwitcher

See also:

Gtk.Stack


Functions:

Description:

The Gtk.StackSwitcher widget acts as a controller for a Gtk.Stack; it shows a row of buttons to switch between the various pages of the associated stack widget.

All the content for the buttons comes from the child properties of the Gtk.Stack.

It is possible to associate multiple Gtk.StackSwitcher widgets with the same stack widget.

The Gtk.StackSwitcher widget was added in 3.10.


Function Details:

new()

new () -> Gtk.Widget

Create a new Gtk.StackSwitcher.

  • Returns: a new Gtk.StackSwitcher.

  • Since: 3.10


set_stack()

set_stack (self, stack:Gtk.Stack=None)

Sets the stack to control.

  • Since: 3.10

get_stack()

get_stack (self) -> Gtk.Stack

Retrieves the stack.See Gtk.StackSwitcher:set_stack().

  • Returns: the stack, or None ifnone has been set explicitly.

  • Since: 3.10


Example:

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

class StackSwitcher(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, 0, 1, 1, 1)

        stackswitcher = Gtk.StackSwitcher()
        stackswitcher.set_stack(stack)
        grid.attach(stackswitcher, 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 = StackSwitcher()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""