Linux and go from the beginning gtk+-3.0 (iii)

Source: Internet
Author: User
Tags gtk

Before we added a button to the window, let's make the button a little richer. and add a label to the window.

First create the example3,c source file.

#include <gtk/gtk.h>Static voidActivate (Gtkapplication *app, gpointer data);//load a picture from a fileGdkpixbuf *create_pixbuf (Const Char*image_name); intMainintARGC,Char**argv) {gtkapplication*app; intApp_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), argc, argv);    G_object_unref (APP); returnApp_status;}Static voidActivate (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), $, $);    Gtk_window_set_position (Gtk_window (window), gtk_win_pos_center); //Create icon control iconsicon = Create_pixbuf ("Icon.png"); //set icons for WindowsGtk_window_set_icon (Gtk_window (window), icon); //Create a button with an accelerator key, hold down ALT, and then press C, which is equivalent to clicking the buttonbutton = Gtk_button_new_with_mnemonic ("_close"); //set an informational cue bar for a buttonGtk_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); g_signal_connect_swapped (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 picture file, second parameter set error variable, no need to set to NULLPixbuf =gdk_pixbuf_new_from_file (Image_name, NULL); if(!pixbuf) {Perror ("gdk_pixbuf_new_from_file () \ n"); returnNULL; }    returnpixbuf;}

Compile and run:

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

Results:

Linux and go from the beginning gtk+-3.0 (iii)

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.