Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';t将小部件附加到我的网格_Python_Python 3.x_Pygobject - Fatal编程技术网

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,我有一个空白窗口。。。为什么?

我指定my
rwy
不是空的

谢谢你的帮助

编辑:
好吧,我试过这个简单的方法:

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(),如果它是一个容器,那么在主容器(通常是主窗口)上调用一次就足以显示所有小部件。