J'ai une grille contenant des étiquettes dans les cadres pour que cela ressemble à une table. Cette grille est insérée dans une boîte verticale dans laquelle les étiquettes enfant directes sont centrées correctement (elles sont emballées dans la boîte de la même manière que la grille).Comment centrer horizontalement un Gtk.Grid dans un Gtk.Box vertical?
Mon code simplifié est ceci:
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()
ce qui est l'interface graphique, il produit: