学了一个学期的linux,感觉收获挺大的,还在网上认识了很多热心的朋友,帮助我解决了不少问题,呵呵···今天最后去了一次机房把我这几天呕心沥血完 成的结课作业交给了老师,顿时心里有点空落落的···现在把我的结课作业发布一下,当做是纪念吧,呵呵····
用gtk写的一个简单的注册界面,填写完用户信息后点击按钮,下面的标签就会发生变化,由原来的几何图形变为欢迎致辞,原打算点击按钮之后,出现用户注册 信息的,无奈没有调出来,有点遗憾,不过毕竟老师上课的时候也没有讲过(老师可奸诈啦,说为了公平起见,最后的结课作业就让我们做没学过的东西),我也是 最近才自学的,可以原谅哈····呵呵···请大家多多指教啦
·········10········20········30········40········50········60········70········80········90
001.#include<gtk/gtk.h>
002.
003.void button_event(GtkWidget*,gpointer*);
004.GtkWidget *passwd;
005.GtkWidget *name;
006.GtkWidget *label0;
007.
008.int main(int argc,char *argv[])
009. {
010. GtkWidget *window;
011. GtkWidget *button;
012. GtkWidget *label;
013. GtkWidget *box;
014. GtkWidget *box1;
015. GtkWidget *box2;
016. GtkWidget *box3;
017. GtkWidget *box4;
018. GtkWidget *mail;
019. GtkWidget *combo;
020. GList *glist=NULL;
021.
022.
023.
024. gtk_init_check(&argc,&argv);
025. window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
026. gtk_signal_connect(GTK_OBJECT(window),"delete_event",G_CALLBACK(gtk_main_quit),NULL);
027. box=gtk_vbox_new(FALSE,0);
028. box1=gtk_hbox_new(FALSE,0);
029. box2=gtk_hbox_new(FALSE,0);
030. box3=gtk_hbox_new(FALSE,0);
031. box4=gtk_hbox_new(FALSE,0);
032.
033.
034.label=gtk_label_new("COME ON!!\nyou are the very man we`re looking for~~~~~");
035. gtk_box_pack_start(GTK_BOX(box),label,FALSE,FALSE,5);
036. gtk_label_set_justify(GTK_LABEL(label),GTK_JUSTIFY_CENTER);
037. gtk_widget_show(label);
038.
039. label=gtk_label_new(" Username ");
040. gtk_box_pack_start(GTK_BOX(box1),label,FALSE,FALSE,0);
041. gtk_widget_show(label);
042.
043. name=gtk_entry_new();
044. gtk_box_pack_start(GTK_BOX(box1),name,FALSE,FALSE,0);
045. gtk_widget_show(name);
046.
047. gtk_box_pack_start(GTK_BOX(box),box1,FALSE,FALSE,5);
048. gtk_widget_show(box1);
049.
050. label=gtk_label_new(" Gender ");
051. gtk_box_pack_start(GTK_BOX(box3),label,FALSE,FALSE,0);
052. gtk_widget_show(label);
053.
054. combo=gtk_combo_new();
055. glist=g_list_append(glist,"female" );
056. glist=g_list_append(glist,"male" );
057. gtk_combo_set_popdown_strings(GTK_COMBO(combo),glist);
058. gtk_container_add(GTK_CONTAINER(box3),combo);
059. gtk_widget_show(combo);
060.
061. gtk_box_pack_start(GTK_BOX(box),box3,FALSE,FALSE,5);
062. gtk_widget_show(box3);
063.
064. label=gtk_label_new("E-mail Address");
065. gtk_box_pack_start(GTK_BOX(box2),label,FALSE,FALSE,0);
066. gtk_widget_show(label);
067.
068. mail=gtk_entry_new();
069. gtk_box_pack_start(GTK_BOX(box2),mail,FALSE,FALSE,0);
070. gtk_widget_show(mail);
071.
072. gtk_box_pack_start(GTK_BOX(box),box2,FALSE,FALSE,5);
073. gtk_widget_show(box2);
074.
075. label=gtk_label_new(" Password ");
076. gtk_label_set_justify(GTK_LABEL(label),GTK_JUSTIFY_CENTER);
077. gtk_box_pack_start(GTK_BOX(box4),label,FALSE,FALSE,5);
078. gtk_widget_show(label);
079.
080. passwd=gtk_entry_new();
081. gtk_entry_set_visibility(GTK_ENTRY(passwd),FALSE);
082. gtk_box_pack_start(GTK_BOX(box4),passwd,FALSE,FALSE,5);
083. gtk_widget_show(passwd);
084.
085. gtk_box_pack_start(GTK_BOX(box),box4,FALSE,FALSE,5);
086. gtk_widget_show(box4);
087.
088. button=gtk_check_button_new_with_label("agree to the Masher Terms and Conditions,\nPrivacy Policy and Code of Conduct");
089. gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,5);
090. gtk_widget_show(button);
091.
092.
093. button=gtk_button_new_with_label("Sign up!");
094. gtk_box_pack_start(GTK_BOX(box),button,TRUE,FALSE,5);
095. gtk_signal_connect(GTK_OBJECT(button),"clicked",GTK_SIGNAL_FUNC(button_event),"********************\n*** successfull ***\n********************\n welcome freshman \n********************\n");
096. gtk_widget_show(button);
097.
098.
099.
100. gtk_entry_prepend_text(GTK_ENTRY(name),"Please input your name!");
101. gtk_entry_prepend_text(GTK_ENTRY(mail),"Please input your E-mail!");
102.
103. label0=gtk_label_new("*\n* *\n* *\n* * * * * *\n * * \n * * \n ******* \n");
104. gtk_box_pack_end(GTK_BOX(box),label0,FALSE,FALSE,5);
105. gtk_label_set_justify(GTK_LABEL(label0),GTK_JUSTIFY_CENTER);
106. gtk_widget_show(label0);
107.
108.
109.
110. gtk_container_add(GTK_CONTAINER(window),box);
111. gtk_widget_show(box);
112. gtk_widget_show(window);
113. gtk_main();
114. return 0;
115. }
116.
117.void button_event(GtkWidget *widget,gpointer *data)
118.{
119. gtk_label_set(GTK_LABEL(label0),(char*)data);
120.}