Gtk basic learning Summary (2), gtk basic learning Summary

Source: Internet
Author: User
Tags gtk

Gtk basic learning Summary (2), gtk basic learning Summary

I. Signals and events

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

// Instance: gtk Control

Int btnOnClick (GtkWidget * widget, int data );

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

 

// Add a Clicked event

GtkButton * btn1 = gtk_button_new ();

Gtk_button_set_label (btn1, "button ");

Gtk_container_add (window, btn1 );

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

Gtk_widget_show (btn1 );

 

2. Gtk Control

// Check box CheckButton

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

CbAgree = gtk_check_button_new ();

Gtk_button_set_label (cbAgree, "I agree with the above agreement .");

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

Gtk_widget_show (cbAgree );

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

 

// Single parameter RadioButton

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

GtkRadioButton * radio2 = gtk_radio_button_new_with_label_from_widget (radio1, "female"); // the same group as 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 );

 

// Text box entry

EntryName = gtk_entry_new ();

Gtk_entry_set_max_length (entryName, 5); // you can specify the maximum length of an input.

Gtk_entry_set_visibility (entryName, FALSE); // set it to the password frame style.

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", "Wu ");

Gtk_combo_box_text_append (cmbGril, "wd", "Wu Dong ");

Gtk_combo_box_text_append (cmbGril, "wxq", "Wu Xiaoqing ");

Gtk_combo_box_set_active_id (cmbGril, "wd ");

// Changed event

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

Gtk_widget_show (cmbGril );

 

// GtkImage, supports JPG, GIF, and PNG, and does not support 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 );

 

// Buttons with images

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 ("OK ");

Gtk_button_set_image (btn, img );

Gtk_container_add (window, btn );

Gtk_widget_show (btn );

 

 

Appendix: The above content is a summary of what I learned after learning the teaching video of Teacher Yang zhongke's "C language is also capable of major events (the third edition.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.