这效果不好:
image_log = gtk.Image()
image_log.set_from_file("test.png")
self.out_button = gtk.Button()
self.out_button.add(image_log)
self.err_button = gtk.Button()
self.err_button.add(image_log)
another_box.pack_start(self.out_button, False)
another_box.pack_start(self.err_button, False)
问题是,image_log 被使用了两次,而 GTK 不喜欢它。有一些 .copy() 方法吗?还是我应该只使用普通的深拷贝?
编辑:看起来在 GTK 中没有克隆对象的默认方法。在这种情况下,工厂会解决问题。
GTK警告:
app/gui.py:248: GtkWarning: gtk_box_pack: assertion `child->parent == NULL' failed
hbox_errlog.pack_start(image_log)