Gtk3 replace child widget with another widget

后端 未结 4 1681
执念已碎
执念已碎 2021-01-17 10:25

I\'m looking for a way to remove a widget from its parent (whatever that may be - a VBox, a Grid, ...) and add a substitute widget in its place.

I found this answer,

4条回答
  •  一个人的身影
    2021-01-17 10:34

    i know how it works with C , i did not try it with python :

     parent = gtk_widget_get_parent(old);
     g_object_ref(_key); /** because gtk_container_remove remove the widget with its reference we have to increment the number of reference if we want to reuse the old widget **/
     gtk_container_remove(GTK_CONTAINER(parent), old);
     gtk_container_add(GTK_CONTAINER(parent), new);
    

    PS : in the case of a VBox or Grid the widget is not inserted int the place of old one , you have to specify the position of insertion (the position of the old whild)

    good luck ,

提交回复
热议问题