1
我有一个网格包含框架内的一些标签,使它看起来像一个表。此网格插入垂直框中,其中直接的子标签正确居中(它们以与网格相同的方式包装在框中)。如何在一个垂直的Gtk.Box中水平居中一个Gtk.Grid?
我的简化代码如下所示:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
window = Gtk.Window()
g = Gtk.Grid() # this should be in the horizontal center of the window
g.attach(Gtk.Label("This should be centered but it is not."), 0, 0, 1, 1)
b = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
b.pack_start(g, True, False, 0) # The same behavior with: b.pack_start(g, True, True, 0)
b.pack_start(Gtk.Label("This label is centered as it should be. Try to resize the window."), True, False, 0)
window.add(b)
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()
,这是它产生的GUI: