1

im creating a GUI with gtk 3 and don't know how to see if a Gtk_container like a gtk box for example is empty , does a function do that ? Does another manipulation can give this information ?

Thanks for the answer .

2 Answers 2

1

GtkContainer does not describe a property with the count number of children. In your application you could track this number since you are the one adding and/or removing children.

Anyway, Widgets that inherit from GtkContainer have two functions/methods that allow you to iterate by all children (w/ or w/o internal children).

Assuming the C base reference:

These are:

I believe that you will be interested in the foreach function/method as suggested by the documentation:

Most applications should use gtk_container_foreach(), rather than gtk_container_forall().

You could also use the function/method gtk_container_get_children ()

This will return a GList with all the non internal children which you could iterate too and get a count.

Since you did not specify a language, C was assumed since it's the base reference for the Gtk framework. Nonetheless, its very easy to extrapolate to another language.

4
  • Thanks a lot for this help , gratefull
    – blablu
    Jun 27, 2020 at 14:04
  • I now have another time need for help , i want to clear a GtkImage in a callback function . This Callback function show an image an i want this image to be reset every time i call this callback function , any help ?
    – blablu
    Jun 27, 2020 at 15:46
  • I already found the gtk_image_clear but it doesnt seams to work so do you have any tutorials on how to use it ?
    – blablu
    Jun 27, 2020 at 15:48
  • I would suggest that you open a new question and give an example of problem you are having, maybe some code. Jun 28, 2020 at 0:58
0
children = gtk_container_get_children(GTK_CONTAINER(vbox));
      
for(iter = children; iter != NULL; iter = g_list_next(iter))
    gtk_widget_destroy(GTK_WIDGET(iter->data));
      
g_list_free(children); 
1
  • 2
    While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
    – Suraj Rao
    Nov 9, 2020 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.