【发布时间】:2016-04-22 01:32:47
【问题描述】:
我需要在 C 中创建按钮数组。我不确定我缺少什么,请帮助我。这是我的数组:
GtkWidget *button[5];
int i;
for ( i =1; i<5; i++)
button[i] = gtk_button_new();
然后我创建其余的按钮...我正在使用 button [i] 然后最后我这样做 i++; 这可能不是最好的方法,但我不确定何时创建数组,如何在我的其余语句中传递按钮 1、按钮 2 等?
请任何帮助表示赞赏。
p.s.我是 C 新手,不要对我苛刻,ty:)
/* Creates a new button with the label "Button 1". */
button[i] = gtk_button_new_with_label ("Button 1");
/* Now when the button is clicked, we call the "callback" function
* with a pointer to "button 1" as its argiument */
g_signal_connect (button[i], "clicked",
G_CALLBACK (callback), "Run button 1");
/* Instead of gtk_container_add, we pack this button into the invisible
* box, which has been packed into the window. */
gtk_box_pack_start (GTK_BOX (box1), button[i], TRUE, TRUE, 0);
/* Always remember this step, this tells GTK that our preparation for
* this button is complete, and it can now be displayed. */
gtk_widget_show (button[i]);
i++;
【问题讨论】:
-
数组索引值以 0 开头。例如
for(i=0;i<5;i++) -
好吧,想想当 i=5 时 i
标签: c arrays button widget gtk