Linux Headquarters

I've installed Linux… now what???

GtkCheckButton – Check Button Widget

Introduction
GtkCheckButton widgets serve the exact same purpose as GtkToggleButtons except that they look differently. Instead of looking like a normal button, GtkCheckButton widgets appear as small check boxes. GtkCheckButton widgets are usually used next to GtkLabels that describe what the option is. Instead of declaring a GtkCheckButton and a GtkLabel and placing them next to each other, a shortcut is to use the gtk_check_button_new_with_label function, which allows you to create the check button and the label in one statement.

Source Code

/*
*File name: checkbutton.c
*/

#include
#include

/*– 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 *check1;
GtkWidget *check2;
GtkWidget *check3;
GtkWidget *hbox;

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

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

/*– Create the hbox –*/
hbox = gtk_hbox_new(FALSE, 0);

/*– Connect the window to the destroyapp function –*/
gtk_signal_connect(GTK_OBJECT(window), “delete_event”, GTK_SIGNAL_FUNC(destroyapp), NULL);

/*– Create the first radio button with a label –*/
check1 = gtk_check_button_new_with_label (“Check 1″);
check2 = gtk_check_button_new_with_label (“Check 2″);
check3 = gtk_check_button_new_with_label (“Check 3″);

/*– Pack all the radio buttons into the hbox –*/
gtk_box_pack_start(GTK_BOX(hbox), check1, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(hbox), check2, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(hbox), check3, TRUE, TRUE, 2);

/*– Add the hbox to the window –*/
gtk_container_add(GTK_CONTAINER(window), hbox);

/*– Add a border to the window to give the button a little room –*/
gtk_container_border_width (GTK_CONTAINER (window), 15);

/*– Display the widgets –*/
gtk_widget_show(check1);
gtk_widget_show(check2);
gtk_widget_show(check3);
gtk_widget_show(hbox);
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 checkbutton.c -o checkbutton `gtk-config –cflags` `gtk-config –libs`

Execute the Program

./checkbutton

What is Related

Comments are closed.

Subscribe to email feed

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Dedicated Linux Serv

Linux is the popular system nowadays, offering all the benefits ...

StarOffice 5.1

Introduction StarOffice 5.1 is a complete office suite with a word ...

AxY FTP

Introduction AxY FTP, formerly known as wxFTP, is a graphical FTP ...

Adobe Acrobat PDF Re

Introduction Many of you are probably familar with Adobe Acrobat Reader ...

Macromedia Shockwave

Introduction Macromedia has developed a version of its popular Shockwave plugin ...

Twitter updates

No public Twitter messages.