Home   |   Guides and Tutorials   |   What's New?   |   Comments   |   About
 

GtkCalendar - Calendar Widget

by Brent Fox
Last Modified: Wednesday, 19-May-2004 11:54:18 EDT

Introduction
    The GtkCalendar widget is used to display a calendar to the screen, one month at a time. For the purpose of this example, we are not setting the date on the calendar. In a real world program, you will want to get the system date and set the date on the calendar accordingly.
Screenshot



Source Code
Source code for this example is also available in the file calendar.c
/*
 *File name: calendar.c
 */

#include <gtk/gtk.h>
#include <glib.h>

/*-- This function allows the program to exit properly when the window is closed --*/
gint destroyapp (GtkWidget *widget, gpointer gdata)
{
  g_print ("Quitting...\n");
  gtk_main_quit();
  return (FALSE);
}

int main (int argc, char *argv[])
{
  /*-- Declare the GTK Widgets used in the program --*/
  GtkWidget *window;
  GtkWidget *calendar;

  /*--  Initialize GTK --*/
  gtk_init (&argc, &argv);

  /*-- Create the new window --*/
  calendar = gtk_calendar_new();

  /*-- Create the new window --*/
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  /*-- Connect the window to the destroyapp function  --*/
  gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL);

  /*-- Add the calendar to the window --*/
  gtk_container_add(GTK_CONTAINER(window), calendar);

  /*-- Display the widgets --*/
  gtk_widget_show(calendar);
  gtk_widget_show(window);

  /*-- Start the GTK event loop --*/
  gtk_main();

  /*-- Return 0 if exit is successful --*/
  return 0;
}

Compile the Source Code
gcc -Wall -g calendar.c -o calendar `gtk-config --cflags` `gtk-config --libs`

Execute the Program
./calendar

What's Related


All Rights Reserved Linux Headquarters © 2000-2007
Linux is a registered trademark of Linus Torvalds
All logos are registered trademarks of their respective owners
Last modified: Wednesday, May 19, 2004