在我的__init__
功能中,我正在尝试做:
builder = gtk.Builder()
builder.add_from_file('main.glade')
builder.connect_signals(Handle())
self.list = builder.get_objects()
现在我想为我的 gui 中的所有小部件添加属性到我的类
for i in self.list:
name = i.get_name()
print name
setattr(self, name, i)
我得到:
<gtk.VBox object at 0x2fd5558 (GtkVBox at 0x2499000)>
<gtk.Button object at 0x2fd5580 (GtkButton at 0x240a1a8)>
<gtk.Button object at 0x2fd55a8 (GtkButton at 0x240a130)>
<gtk.Button object at 0x2fd55d0 (GtkButton at 0x240a0b8)>
<gtk.Window object at 0x2fd55f8 (GtkWindow at 0x2495010)>
<gtk.HBox object at 0x2fd5620 (GtkHBox at 0x2499058)>
<gtk.Button object at 0x2fd5648 (GtkButton at 0x240a220)>
<gtk.TextView object at 0x2fd5670 (GtkTextView at 0x249d060)>
而不是我给这些小部件的具体名称
您对如何同时初始化所有小部件有想法吗?