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: