【发布时间】:2014-12-07 13:34:40
【问题描述】:
我正在寻找一种方法来从其父级中删除一个小部件(无论它是什么 - VBox、一个网格等)并在其位置添加一个替代小部件。
我找到了this answer,但我似乎无法让它与 Gtk3 一起使用。
这是我尝试过的:
from gi.repository import Gtk
def replace_widget(old, new):
parent= old.get_parent()
props= {}
for key in Gtk.ContainerClass.list_child_properties(type(parent)):
props[key.name]= parent.child_get_property(old, key.name)
parent.remove(old)
parent.add_with_properties(new, **props)
但是对Gtk.ContainerClass.list_child_properties 的调用引发了
TypeError: argument self: Expected a Gtk.ContainerClass, but got gi.repository.Gtk.GObjectMeta
它也不接受容器小部件的实例。对于我的生活,我无法弄清楚我应该传递什么参数。
P.S.:我知道我可以在容器和子小部件之间添加另一个小部件,但我不想这样做。
更新:我想这还不够清楚:替代小部件应该与原始小部件位于同一位置,具有相同的打包属性。
【问题讨论】:
-
这是一个如何使用树视图的示例:stackoverflow.com/questions/27747172/…