Code: Select all
Attempting to add a widget with type GtkButton 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 GtkButton
horizontal using GtkGrid
Code: Select all
#include <gtk/gtk.h>
int main( int argc,char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button2;
GtkWidget *grid;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* Let's set the border width of the window to 20.
* You may play with the value and see the
* difference. */
gtk_container_set_border_width
(GTK_CONTAINER (window), 10);
button = gtk_button_new_with_label ("Hello World!");
button2 = gtk_button_new_with_label ("Hello World2!");
/* Here we construct the container that is going pack our buttons */
grid = gtk_grid_new ();
/* Pack the container in the window */
gtk_container_add (GTK_CONTAINER (window), grid);
gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), button2, 1, 0, 1, 1);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}
Code: Select all
#include <gtk/gtk.h>
int main( int argc,char *argv[] )
{
GtkWidget *window;
GtkWidget *button;
GtkWidget *button2;
GtkWidget *grid;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* Let's set the border width of the window to 20.
* You may play with the value and see the
* difference. */
gtk_container_set_border_width
(GTK_CONTAINER (window), 10);
button = gtk_button_new_with_label ("Hello World!");
button2 = gtk_button_new_with_label ("Hello World2!");
/* Here we construct the container that is going pack our buttons */
grid = gtk_grid_new ();
/* Pack the container in the window */
gtk_container_add (GTK_CONTAINER (window), grid);
gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), button2, 0, 1, 1, 1);
gtk_widget_show_all(window);
gtk_main ();
return 0;
}
Reference
https://developer.gnome.org/gtk-tutoria ... /c354.html
Packing Tutorial https://developer.gnome.org/gtk3/stable/ch01s02.html