gpt4 book ai didi

python - GTK 对话框边距不起作用

转载 作者:行者123 更新时间:2023-11-30 22:14:23 25 4
gpt4 key购买 nike

我创建了一个带有网格的小对话框。这是它:

enter image description here

但我不明白为什么边距不起作用:

class PreferencesDialog(Gtk.Dialog):

def __init__(self, parent):
Gtk.Dialog.__init__(self, "Preferences", parent, 0)

self.set_default_size(300, 300)

grid = Gtk.Grid(column_spacing=10,
row_spacing=10)

label = Gtk.Label("Custom Location")
switch = Gtk.Switch()
switch.set_active(False)

grid.add(label)
grid.margin_left = 20
grid.margin_right = 20
grid.margin_top = 20
grid.margin_bottom = 20

grid.attach(switch, 1, 0, 1, 1)

box = self.get_content_area()
box.add(grid)
self.show_all()

我发现窗口大小:300x300 不再起作用。你能帮我吗?

最佳答案

Gtk 小部件基于 GObject ,这意味着您必须通过 props attribute 访问小部件的属性。 :

grid.props.margin_left = 20
grid.props.margin_right = 20
grid.props.margin_top = 20
grid.props.margin_bottom = 20

或者,您可以使用 setter functions :

grid.set_margin_left(20)
grid.set_margin_right(20)
grid.set_margin_top(20)
grid.set_margin_bottom(20)

关于python - GTK 对话框边距不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50540159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com