tags:

views:

84

answers:

2
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
...
frame = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), frame);
...

The above code will generate the warning below:

Gtk-WARNING **: Attempting to add a widget with type GtkFixed to a GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one widget at a time; it already contains a widget of type GtkVBox

Which results in frame is not shown in the window.

How can I make both vbox and frame show?

+1  A: 

Put them both in a surrounding vbox (if you want to stack them vertically, that is):

parentVbox = gtk_vbox_new(FALSE, 0);

vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(parentVbox), vbox, TRUE, TRUE, 0);
...
frame = gtk_fixed_new();
gtk_box_pack_start(GTK_BOX(parentVbox), frame, TRUE, 0);
...
gtk_container_add(GTK_CONTAINER(window), parentVbox);
unwind
I don't know why,but it only works after I change `GTK_VBOX` to `GTK_BOX`,is it typo?
Gtker
@Runner: Yes, it is. Thanks!
unwind
A: 

The error you are having is because every widget can only contain one widget (you want vbox and frame to be contained by window), even though the widget contained may be a complex one with several other widgets contained.

To put a widget inside a box you have to use gtk_box_pack_start (). Gnome Reference Manual link: http://library.gnome.org/devel/gtk/stable/GtkBox.html#gtk-box-pack-start

vbox = gtk_vbox_new(FALSE, 0);
frame = gtk_fixed_new();
gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); //the frame goes inside vbox
...
gtk_container_add(GTK_CONTAINER(window), vbox); //the vbox is contained by window
dallen
Widgets derived from GtkBox can manage variable number of widgets.
dallen
How should I write the proper code?I'm not familiar with gtk yet.
Gtker