I hope someone can help me.
My Aim
- creating a simple multi paged GTK application with python
- pages should be switched by using a sidebar or a top bar
- each page should be able to contain multiple elements (e.g. a few buttons, labels, ...) arranged in a grid or something
My code so far (some copy&paste from free sources and some modifications)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class StackSidebar(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="application title")
self.set_default_size(900, 600)
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)
label = Gtk.Label("label 1 text inside")
name = "label1"
title = "label 1 name"
stack.add_titled(label, name, title)
label = Gtk.Label("label 2 text inside")
name = "label2"
title = "label 2 name"
stack.add_titled(label, name, title)
label = Gtk.Label("label 3 text inside")
name = "label3"
title = "label 3 name"
stack.add_titled(label, name, title)
window = StackSidebar()
window.set_wmclass ("application title", "application title")
window.show_all()
Gtk.main()
Result
Click link to see the running application
Problem
I am only able to see/create just one label within each page. See label = Gtk.Label("label 1 text inside")
. As stated before, I would like to arrange a few buttons and so on but do not have any idea how to begin that.
Could you help? Is that even possible? Is my approach OK or should I use something like GtkNotebook? Thanks in advance.