Computer Programming/Event driven programming

In this type of programming, a section of code is written to respond to each event. Events can be user events such as button clicks or mouse moves. Events can also be generated within the computer, for example timer events. Finally, the programmer can generate events.

Responding to an event is sometimes termed handling an event.

The program simply consists of sections that respond to events. These may, in turn use other sections (procedures, methods).

Example edit

This simple GTK+ program makes a GUI, with a button, that responds to the click event, after we enter a main-loop given by the gtk_main() function. When ever events occur, like "clicked" event, we lookup event-handlers connected to it via g_signal_connect() function, and delegate functions by invoking them. In this case the handler, btn_clicked is invoked.

#    GtkBook :
#       A Book for GTK+ users.
#    Copyright (C) July, 2005 Muthiah Annamalai
#    This program is free software; Licensed under GPL.

btn_clicked(GtkWidget *w,gpointer data)
  GtkButton *btn=GTK_BUTTON(w);
  gtk_button_set_label(btn,"You Cliked Me");  
  return TRUE;

int main()
  GtkWidget *w,*box,*btn;


  gtk_window_set_title(GTK_WINDOW(w),"Button Widget");
  btn=gtk_button_new_with_label("Hello World! Click Me:");


  return 0;

gcc -o button button.c -Wall -ggdb `pkg-config gtk+-2.0  --cflags --libs`