Reputation: 19
I have written a C-program and am studying GTK and Glade to build a GUI and now I am stuck for at least two days:
I need a notebook with one tab. In this tab is a button, if clicked a new tab is added.
I found: 'gtk_notebook_append_page(notebook_pointer, tab_content_pointer, label)' but whatever I do it doesn't work. Especially I am not sure what to take as tab_content. I get one out of three error messages: it complains that it is top level and can't get a parent or it has already a parent or the new tab just can't be inserted.
Does anyone know what to take in glade to be used as tab_content? Or knows an example where I could learn that?
Or do I need to dump glade and write everything in C-code? I found examples for that.
Thanks for your help.
Upvotes: 1
Views: 2591
Reputation: 5440
Draw a notebook with Glade. If you right - click on the tab you want to change, you can delete its contents. (A tab can contain a single widget, though you can put in a HBox or a Grid to combine several).
Once deleted, you can insert any other widget there. Here is an example:
A window with a notebook. First tab contents deleted
Inserted a Box, but by default it's vertical, so...
I changed the property to horizontal
I inserted an image widget in the first space, and a checkbutton in the second. (Change the computer's theme to make is a little more visible.
If you want to add pages from you C-code you can do that too, just get a reference to the notebook, and then modify the tab contents.
As a note, I'd recommend looking at using Python as manager of your GUI. Managing GUIs in Gtk and C - using Glade or not - is tedious. There are several example on the net about how to do that:
This code adds a new tab perfectly here:
notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook1"));
if (!notebook) {
g_critical ("Widget \"%s\" is missing in file %s.",
TOP_WINDOW, "notebook1");
}
tab_label = gtk_label_new ("New page's tab");
page_contents = gtk_label_new ("New page's contents");
gtk_notebook_append_page(notebook, page_contents, tab_label);
Note that you have to put "notebook1" in the ID field of the notebook's widget in Glade.
Upvotes: 1