我有一个包含一些标签的网格,这些标签在框架内,以使其看起来像一个表格。这个网格插入到一个垂直的盒子中,其中直接子标签被正确地居中(它们以与网格相同的方式打包在盒子中)。
我的简化代码如下:
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界面:
hexpand
? - Jack M