Re: Random Number of Buttons



On 4/20/06, 3saul <saul_lethbridge hotmail com> wrote:
I'm wanting to know the best way to declare a random number of buttons for my
gtk app. The number will changed depending on the argument passed to my app.

Just use an array of GtkWidget pointers. For example (untested):

GtkWidget **
add_buttons( GtkWidget *parent, int n )
{
  GtkWidget **buttons = g_new( GtkWidget *, n );

  for( i = 0; i < n ; i++ ) {
    char label[256];

    snprintf( label, 256, "button %d", i );
    buttons[i] = gtk_button_new_with_label( label );
    gtk_contaner_add( GTK_CONTAINER( parent ), buttons[i] );
    gtk_widget_show( buttons[i] );
  }

  return( buttons );
}

Creates and returns an array of n buttons.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]