#include <stdio.h> #include <stdlib.h> #include "gtk/gtk.h"
gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data ) { gtk_main_quit (); return FALSE; }
int main( int argc, char *argv[]) { GtkWidget *window; GtkWidget *button; GtkWidget *box1; GtkWidget *box2; GtkWidget *separator; GtkWidget *label; GtkWidget *quitbox; int which; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "Hello Buttons\n"); g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); box1 = gtk_vbox_new (FALSE, 0); //下面函数中第一个参数表示控制每个物件是否有同样的宽或高
box2 = gtk_hbox_new (TRUE, 0); label = gtk_label_new ("first:"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); separator = gtk_hseparator_new (); gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 5); gtk_widget_show (separator); { button = gtk_button_new_with_label ("111111111"); //expand = TRUE的话它们会填满box中所有额外的空间
//fill=TRUE该物件会自行产生额外空间
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 10); gtk_widget_show (button); button = gtk_button_new_with_label ("2"); gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 10); gtk_widget_show (button); button = gtk_button_new_with_label ("3"); gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 10); gtk_widget_show (button); } gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2);
quitbox = gtk_hbox_new (FALSE, 0); button = gtk_button_new_with_label ("Quit"); g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (gtk_main_quit), window); gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (button); gtk_widget_show (quitbox); gtk_widget_show (box1); gtk_widget_show (window); gtk_main (); return 0; }
|