GTK + first knowledge --- graphic interfaces on the tall node, first knowledge of gtk --- graphics

Source: Internet
Author: User
Tags cairo gtk

GTK + first knowledge --- graphic interfaces on the tall node, first knowledge of gtk --- graphics

GTK +, or GIMP tool component, is a set of multi-platform components for creating graphical user interfaces. GTK + provides a complete set of components, not only for small tool development, but also for a complete project suite.

Like our familiar gnome desktop, GIMP image processing software on various system platforms, VMWare workstations, and gedit text editors on OS X and Windows vista are all created using GTK.

GTK + is written in C language, but has been designed to support multi-language frameworks. For example, GTK + can be used in Perl and python to quickly create desktop applications. at the same time, GObject is implemented using GObject. GObject is an object-oriented framework developed for C. Therefore, GTK + supports object-oriented programming. GTK + is event-driven. this set of event listening, such as clicking a button, will pass the event to your application for response.

Below we will build our development environment:
First, we need to understand that GTK + itself depends on the following libraries:

1:Glib2:pangp3:ATK4:GDK5:GdkPixbuf6:Cairo

Let's take a look at these function libraries:

Glib is a common tool function library. it provides some data types, string tools, error notifications, message queues and threads. pango is a function library for internationalization and localization. ATK is a tool function package that provides the function of creating shortcuts. GDK is a function library that provides some underlying "Graphical implementation" and "window implementation" methods for the entire GTK + function graphics system. the GDKPixbuf function library is used to load images and maintain image cache ". cairo is a function library used to create two-dimensional images.

First, we need to install the GTK + function library in our ubuntu system:

sudo apt-get install gtk2 gtk2-devel gtk2-devel-docs

Secondly, we need to know how to compile our program after we finish writing our program. That's good to say, just use gcc to compile it. yes, gcc is used for compilation, But how should we specify the location of the function library required during compilation? Here we will use a tool named "pkg-config" which provides various installation libraries. suppose we want to compile our hello. c program, we need to write as follows:

gcc -o hello hello.c `pkg-config --libs --cflags gtk+2.0`

Note that the anti-reference number is used to cause pkg-config. The anti-reference number is the key on the left of the number "1" on your keyboard. let's write a hello World Program:

Hello. c

# Include <gtk/gtk. h>/** the simplest GTK desktop program * is just a small program that generates a window */int main (int argc, char * argv []) {GtkWidget * window; // gtk_init (& argc, & argv); // initialize the entire GTK + program, which is an essential part of every GTK + program./** generate a component-GtkWindow, the type of this form * Is GTK_WINDOW_TOPLEVEL. The toplevel window has a * title bar and border */window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); // required, display the component gtk_main (); // enter the main loop and wait for the event to return 0 ;}

The following code is used for compilation:

gcc -o hello helloc. `pkg-config --libs --cflags gtk+2.0`

The following is the result after running:

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.