Linux and then go from scratch GTK +-3.0 (3), gtk-3.0

Source: Internet
Author: User

Linux and then go from scratch GTK +-3.0 (3), gtk-3.0

Previously, we added a button for the window. Next, we will enrich the button. And add values to the window.

First, create the source file example3 and c.

# Include <gtk/gtk. h> static void activate (GtkApplication * app, gpointer data); // load an image GdkPixbuf * create_pixbuf (const char * image_name) from the file; int main (int argc, char ** argv) {GtkApplication * app; int app_status; app = gtk_application_new ("org. rain. gtk ", G_APPLICATION_FLAGS_NONE); g_signal_connect (app," activate ", G_CALLBACK (activate), NULL); app_status = g_application_run (G_APPLICATION (app), ar Gc, argv); g_object_unref (app); return app_status;} static void activate (GtkApplication * app, gpointer data) {GtkWidget * window; GdkPixbuf * icon; GtkWidget * button; gtkWidget * button_box; window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "icon test"); gtk_window_set_default_size (GTK_WINDOW (window), 200,200 ); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN _ POS_CENTER); // create the icon control icon = create_pixbuf ("icon.png"); // set the window icon gtk_window_set_icon (GTK_WINDOW (window), icon ); // create a button with the acceleration key, hold down Alt and press C, which is equivalent to clicking the button = gtk_button_new_with_mnemonic ("_ Close "); // set a message prompt for the button: gtk_widget_set_tooltip_text (button, "Click button to quit. "); button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_container_add (GTK_CONTAINER (button_box), button ); Gtk_container_add (GTK_CONTAINER (window), button_box); trim (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); g_object_unref (icon); gtk_widget_show_all (window );} gdkPixbuf * create_pixbuf (const char * image_name) {GdkPixbuf * pixbuf; // load the image file. If the second parameter sets an error variable, set it to NULL pixbuf = gdk_buf_new_from_file (image_name, NULL); if (! Pixbuf) {perror ("gdk_pixbuf_new_from_file () \ n"); return NULL ;}return pixbuf ;}

Compile and run:

gcc example.c `pkg-config --cflags --libs gtk+-3.0`./a.out

Result:

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.