Linux from the beginning to go GTK +-3.0 (A), gtk-3.0

Source: Internet
Author: User

Linux from the beginning to go GTK +-3.0 (A), gtk-3.0

Originally, due to project requirements, I had been studying GTK + 2.0 graphics development for a while in Linux. After a while, I wanted to learn more about GTK.

This time, I learned GTK +-3.0 from the beginning, wrote a blog post for later viewing, and also for beginners.

  Installation Environment Reference:

Fedora: http://www.cnblogs.com/watsonlong/archive/2011/04/06/2006989.html

Ubuntu: http://www.cnblogs.com/niocai/archive/2011/07/15/2107472.html

Arch: Run sudo pacman-S gtk3 directly.

  Note:GTK3 is used, and most of the above are GTK2. Install GTK3 in the same way.

 

First, we learned how to create a blank window. Create a source file named example. c. The content is as follows:

1 # include <gtk/gtk. h> // the header file to be included in each GTK program, which declares many types, such as function prototype 2 3 static void activate (GtkApplication * app, gpointer data) 4 {5 GtkWidget * window; // declare a window 6 7 window = gtk_application_window_new (app); // create a window for the app 8 9 gtk_window_set_title (GTK_WINDOW (window ), "Application"); // set the title of the window 10 gtk_window_set_default_size (GTK_WINDOW (window), 200,200); // set the default size of the window to 200 pixels in length and width, and 11 gtk_widget_show_all (window ); // display window 12} 13 14 15 int main (int argc, char ** argv) // main function 16 {17 GtkApplication * app; // declare to create a GtkApplicatin object named app18 int app_status; // return value 19 20 app = gtk_application_new ("org. rain. gtk ", G_APPLICATION_FLAGS_NONE); // create an application21 g_signal_connect (app," activate ", G_CALLBACK (activate), NULL); // connection signal. When initializing the app, call the activate function 22 app_status = g_application_run (G_APPLICATION (app), argc, argv); // run app23 24 g_object_unref (app); // destroy app25 26 return app_status; 27}

Compile the source file and execute the generated example executable file as follows.

gcc example.c `pkg-config --cflags --libs gtk+-3.0` -Wall -o example./example

The running result is as follows:

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.