#include #include #include static GtkWidget *entry1, *entry2, *entry3; static void button_clicked (void) { const char *str1 = gtk_entry_get_text (GTK_ENTRY (entry1)); const char *str2 = gtk_entry_get_text (GTK_ENTRY (entry2)); int i1 = atoi (str1); int i2 = atoi (str2); char buf[10]; snprintf (buf, 10, "%i", i1+i2); gtk_entry_set_text (GTK_ENTRY (entry3), buf); } int main (int argc, char *argv[]) { GtkWidget *win; GtkWidget *vbox; GtkWidget *button; gtk_init (&argc, &argv); win = gtk_window_new (GTK_WINDOW_TOPLEVEL); vbox = gtk_vbox_new (TRUE, 0); gtk_container_add (GTK_CONTAINER (win), vbox); entry1 = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (vbox), entry1, FALSE, FALSE, 0); entry2 = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (vbox), entry2, FALSE, FALSE, 0); button = gtk_button_new_with_label ("Add"); gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (button_clicked), NULL); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); entry3 = gtk_entry_new (); gtk_box_pack_start (GTK_BOX (vbox), entry3, FALSE, FALSE, 0); gtk_widget_show_all (win); gtk_main (); return 0; }