Python Can';t将小部件附加到我的网格
我正在尝试创建带有循环的小部件。这就是我所尝试的:Python Can';t将小部件附加到我的网格,python,python-3.x,pygobject,Python,Python 3.x,Pygobject,我正在尝试创建带有循环的小部件。这就是我所尝试的: def set_runways(self, airfield): i = 0 for rwy in airfield['Runways']: frame = Gtk.Frame() frame.set_label('-'.join([rwy['Runway_1'], rwy['Runway_2']])) frame.set_shadow_ty
def set_runways(self, airfield):
i = 0
for rwy in airfield['Runways']:
frame = Gtk.Frame()
frame.set_label('-'.join([rwy['Runway_1'], rwy['Runway_2']]))
frame.set_shadow_type(1)
self.runways_layout.attach(frame, (i / 2), (i % 2), 1, 1)
rwy_layout = Gtk.Grid()
frame.add(rwy_layout)
# Just for testing :
label = Gtk.Label('Hello, World')
rwy_layout.attach(label, 0, 0, 1, 1)
我使用self.runways\u layout=builder.get_对象('runwaysGrid')
将runways\u布局导入我的中,它是一个Gtk.Grid
,然后使用self.set\u跑道(机场)
调用我的函数。但即使这样,我的窗口也不会显示Hello World,我有一个空白窗口。。。为什么?
我指定myrwy
不是空的
谢谢你的帮助
编辑:
好吧,我试过这个简单的方法:
self.runways_layout = builder.get_object('runwaysGrid')
label = Gtk.Label('Coucou')
self.runways_layout.attach(label, 0, 0, 1, 1)
而且它也不起作用。。。O_O好的,我找到了一个解决方案,我必须做:
self.runways_layout = builder.get_object('runwaysGrid')
label = Gtk.Label('Coucou')
self.runways_layout.attach(label, 0, 0, 1, 1)
label.show() # Add this and it works...
但是为什么?为什么是什么意思?阅读参考中的show(9)和show_all()方法,您会发现。在我的另一个窗口中,我不必编写label.show()
。我不明白为什么。show_all()递归调用show(),如果它是一个容器,那么在主容器(通常是主窗口)上调用一次就足以显示所有小部件。