【问题标题】:How does GTK grid container positioning works?GTK 网格容器定位是如何工作的?
【发布时间】:2022-10-13 04:09:19
【问题描述】:

这是我的代码

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

class Window(Gtk.Window):
    def __init__(self):
        super().__init__(title="GUi")
        self.ui()

    def ui(self):
        self.connect("destroy", Gtk.main_quit)
        button1 = Gtk.Button(label="Button 1")
        button2 = Gtk.Button(label="Button 2")
        grid = Gtk.Grid()
        self.add(grid)
        grid.attach(button1, 0, 0, 1, 1)
        grid.attach(button2, 0, 3, 2, 2)
        self.show_all()

window = Window()
Gtk.main()

this 是我的输出,但我已经提到按钮 2 出现在第 3 列,并将其行和列跨度设为 2,但是这两个都没有按预期工作我做错了什么?

【问题讨论】:

  • 这回答了你的问题了吗? Insert empty row in GtkGrid c
  • 另外,请注意,当调用它时:grid.attach(button2, 0, 3, 2, 2),第一个整数参数是列。这意味着button2 不在第三列,而是在第一列(从 0 开始)。见the reference。

标签: python user-interface grid gtk positioning


【解决方案1】:

我得到的印象是您正在尝试将按钮彼此并排放置,并在它们之间留出空间。查看此链接,其中提到了 grid 以更好地了解 grid.attach(a,b,c,d,e) 的参数是什么。

a) The child parameter is the Gtk.Widget to add.

b) left is the column number to attach the left side of child to.

c) top indicates the row number to attach the top side of child to.

d) and e)width and height indicate the number of columns that the child will span, and the number of rows that the child will span, respectively.

https://python-gtk-3-tutorial.readthedocs.io/en/latest/layout.html

如果不使用类似的东西,您将无法放置空间。

    grid.set_row_spacing(20)
    grid.set_column_spacing(20)

或者可能是单元格填充或按钮对齐。有关更多信息,请查看此链接 https://athenajc.gitbooks.io/python-gtk-3-api/content/gtk-group/gtkgrid.html

在考虑大小和定位时请记住,它们是从类继承的。定位很棘手,因为您无法真正在两者之间留出空间。

希望这会有所帮助。祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    相关资源
    最近更新 更多