#include <gtk/gtk.h>
GtkWidget* label;
void youqian(GtkButton* button, gpointer user_data)
{
const char* haha = gtk_button_get_label(button);
const char* xixi = gtk_label_get_label(GTK_LABEL(label));
int xixixi = atoi(xixi);
if(strcmp("-", haha) == 0)
{
if(xixixi != 0)
{
xixixi–;
}
}
else
{
xixixi++;
}
char lala[10] = “”;
sprintf(lala, “%d”, xixixi);
gtk_label_set_text(GTK_LABEL(label), lala);
}
int main(int argc, char argv[])
{
gtk_init(&argc, &argv);
GtkWidget window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window, 400, 300);
GtkWidget* vbox = gtk_vbox_new(TRUE, 20);
gtk_container_add(GTK_CONTAINER(window), vbox);
label = gtk_label_new(“0”);
gtk_container_add(GTK_CONTAINER(vbox),label);
GtkWidget* hbox = gtk_hbox_new(TRUE, 30);
gtk_container_add(GTK_CONTAINER(vbox), hbox);
GtkWidget* button1 = gtk_button_new_with_label("-");
GtkWidget* button2 = gtk_button_new_with_label("+");
gtk_container_add(GTK_CONTAINER(hbox), button1);
gtk_container_add(GTK_CONTAINER(hbox), button2);
g_signal_connect(button1, "pressed", G_CALLBACK(youqian), NULL);
g_signal_connect(button2, "pressed", G_CALLBACK(youqian), NULL);
g_signal_connect(window,"destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}