我希望有人可以帮助我。
我的目标
到目前为止我的代码(从免费资源和一些修改中复制和粘贴)
#!/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()
结果
Click link to see the running application
问题
我只能在每个页面中看到/创建一个标签。见label = Gtk.Label("label 1 text inside")
。如前所述,我想安排一些按钮等,但不知道如何开始。
答案 0 :(得分:0)
感谢您的帮助。我看了GtkGrid,效果很好。
这是我的解决方案(摘录)
# See initial post for previous code
grid2 = Gtk.Grid()
button1 = Gtk.Button(label="Button 1")
label1 = Gtk.Label("This is a test label")
button3 = Gtk.Button(label="Button 3")
button4 = Gtk.Button(label="Button 4")
button5 = Gtk.Button(label="Button 5")
button6 = Gtk.Button(label="Button 6")
grid2.add(button1)
grid2.attach(label1, 1, 0, 2, 1)
grid2.attach_next_to(button3, button1, Gtk.PositionType.BOTTOM, 1, 2)
grid2.attach_next_to(button4, button3, Gtk.PositionType.RIGHT, 2, 1)
grid2.attach(button5, 1, 2, 1, 1)
grid2.attach_next_to(button6, button5, Gtk.PositionType.RIGHT, 1, 1)
name = "page3"
title = "page3-title"
stack.add_titled(grid2, name, title)
# See initial post for next code
<强>结果强>