我有一个这样的盒子:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
[...]
box_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
box_outer.pack_start(Gtk.Label('Label1'), False, False, 100)
box_outer.pack_start(Gtk.Label('Label2'), False, False, 0)
Run Code Online (Sandbox Code Playgroud)
我希望第一个标签距顶部 100 像素。第二个标签应位于其正下方。据我发现,填充参数始终设置所有四个方向的填充。怎样才能只设置一个方向呢?
用于Widget.set_margin_top()小部件顶部的边距(而不是填充或间距)。
https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/Widget.html#Gtk.Widget.set_margin_top
所以而不是
box_outer.pack_start(Gtk.Label('Label1'), False, False, 100)
Run Code Online (Sandbox Code Playgroud)
你会用
label = Gtk.Label('Label1')
label.set_margin_top(100)
box_outer.pack_start(label, False, False, 0)
Run Code Online (Sandbox Code Playgroud)