首页 > 代码库 > Gtk基础学习总结(二)

Gtk基础学习总结(二)

一、信号、事件

  void g_signal_connect(instance,char* signalName,callback,gpointerobject);

  //instance:gtk控件

  int btnOnClick(GtkWidget *widget,int data);

  例:   g_signal_connect(window,"destroy",gtk_main_quit,NULL);

 

//添加Clicked事件

  GtkButton *btn1=gtk_button_new();

  gtk_button_set_label(btn1,"按钮");

  gtk_container_add(window,btn1);

  g_signal_connect(btn1,"clicked",btn1OnClicked,NULL);

  gtk_widget_show(btn1);

 

二、Gtk控件

//复选框CheckButton

  //GtkCheckButton *cb1=gtk_check_button_new_with_label("嘿嘿");

  cbAgree=gtk_check_button_new();

  gtk_button_set_label(cbAgree,"我同意以上协议.");

  gtk_box_pack_start(box,cbAgree,FALSE,FALSE,0);

  gtk_widget_show(cbAgree);

  g_signal_connect(cbAgree,"clicked",cbAgreeOnClick,NULL);

 

//单选框RadioButton

  GtkRadioButton *radio1=gtk_radio_button_new_with_label(NULL,"男");

  GtkRadioButton *radio2=gtk_radio_button_new_with_label_from_widget(radio1,"女"); // 和radio1同一组

  gtk_box_pack_start(box,radio1,FALSE,FALSE,0);

  gtk_box_pack_start(box,radio2,FALSE,FALSE,0);

  gtk_widget_show(radio1);

  gtk_widget_show(radio2);

 

//文本框entry

  entryName=gtk_entry_new();

  gtk_entry_set_max_length(entryName,5); //设置输入的最大长度

  gtk_entry_set_visibility(entryName,FALSE); //设置为密码框风格

  gtk_box_pack_start(box,entryName,FALSE,FALSE,0);

  gtk_widget_show(entryName);

 

//标签label

  labelResult=gtk_label_new("");

  gtk_box_pack_start(box,labelResult,FALSE,FALSE,0);

  gtk_widget_show(labelResult);

 

//组合框ComboBoxText

  cmbGril=gtk_combo_box_text_new();

  gtk_box_pack_start(box,cmbGril,FALSE,FALSE,0);

  gtk_combo_box_text_append(cmbGril,"wm","吴淼");

  gtk_combo_box_text_append(cmbGril,"wd","吴东");

  gtk_combo_box_text_append (cmbGril,"wxq","吴晓青");

  gtk_combo_box_set_active_id(cmbGril,"wd");

  //changed事件

  g_signal_connect(cmbGril,"changed",cmbGrilOnChanged,NULL);

  gtk_widget_show(cmbGril);

 

//GtkImage,支持JPG、GIF、PNG等,不支持BMP GtkImage

  *img1=gtk_image_new();

  //gtk_image_set_from_file(img1,"D:\\00_13.jpg");

  gtk_image_set_from_stock(img1,GTK_STOCK_ADD,GTK_ICON_SIZE_DIALOG);

  gtk_box_pack_start(box,img1,FALSE,FALSE,0); gtk_widget_show(img1);

 

 //带图片按钮

  GtkImage *img=gtk_image_new();

  gtk_image_set_from_stock(img,GTK_STOCK_APPLY,GTK_ICON_SIZE_BUTTON);

  gtk_widget_show(img);

  GtkButton *btn=gtk_button_new_with_label("确定");

  gtk_button_set_image(btn,img);

  gtk_container_add(window,btn );

  gtk_widget_show(btn);

 

 

附:以上内容为本人学习了杨中科老师的《C语言也能干大事(第三版)》的教学视频之后,对所学的内容进行的总结。

 

Gtk基础学习总结(二)