user2453107
user2453107

Reputation: 11

How to fill a gtk grid with buttons?

I remember there was a formula in C to fill automatically a grid with buttons, and I can't find the page where I found it, can someone help me with that? I remember there were two FOR in use. Its is in GTK+ 3.0 and on C.

Upvotes: 1

Views: 1580

Answers (1)

LiuLang
LiuLang

Reputation: 773

Like this:

// insert 9 buttons to a grid, 3x3.
void fill_grid_with_buttons(GtkWidget *grid) 
{
  GtkWidget *button;
  int i, j;

  for (i = 0; i < 3; i += 1) {
    for (j = 0; j < 3; j += 1) {
      button = gtk_button_new_with_label ("label");
      gtk_grid_attach (GTK_GRID (grid), button, i, j, 1, 1);
    }
  }
}

Upvotes: 1

Related Questions