Re: Random Number of Buttons
- From: "John Cupitt" <jcupitt gmail com>
- To: 3saul <saul_lethbridge hotmail com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Random Number of Buttons
- Date: Thu, 20 Apr 2006 13:37:13 +0100
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]