GTK re-pick--00

Source: Internet
Author: User
Tags gtk

(a): written in front

From now on, I am going to learn the gtk+2.0 library for the interface program development under Linux. From the point of view of our programmers, the first program that comes into contact is certainly hello world. So we're going to learn from Hello World now. Here is just a GTK + blank window, the main purpose is to first feel the development of GTK +, since he is a library, before I have qtgui aspects of development experience, it is estimated that learning should not be very laborious.

(ii): First knowledge of GTK +

1: What is GTK +

GTK +, or the Gimp suite, is a multi-platform tool suite for creating graphical user interfaces. GTK + provides a complete set of component libraries, whether it's a small tool development or a large application development.

2: Where can I use

GTK + can be used anywhere. As long as you have a GTK + graphics library installed on your platform, you can develop and use GTK + on any platform. GTK + is a cross-platform and provides an easy-to-use API to accelerate your development time. Let's take a look at the programs that the official web site has developed using GTK +:

Languages supported by 3:gtk+

GTK + is written in C, but he has now been designed to support many programming languages, not just C + +. Let's take a look at the list of supported languages for GTK + locks:

4:gtk+ further understanding

GTK + is a part tool kit. He was developed by the C language, using GObject, an object-oriented framework for C implementation. Components are organized at one level. The window component is the primary container. The user interface is then built by adding buttons, drop-down menus, input boxes, and other components to the window. If you are creating a complex user structure, it is recommended that you use Gtkbuilder and his dedicated markup description language for GTK instead of manually embedding it in the interface. You can use a visual user Interface Editor, just like Glade.

GTK is event-driven. A suite listens for events, such as a click event on a button, and passes the event to your app. Before we develop the GTK + application, we need to install gtk+2.0 and library functions.

(c): Hello World

Now we need to create a new C program to write the simplest GTK + program.

1: Create a new hello.c file
2: Contains the header files we need to build the GTK + program Gtk/gtk.h
3: Initialize the entire GTK + program
4: Add Window
5: Display window
6: Enter the main loop

Let's take a look at our code:

#include <gtk/gtk.h>int main(int argc,char *argv[]){    GtkWidget *window;    // 初始化GTK+程序,必不可少    gtk_init(&argc,&argv);    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    // 生成窗体之后需要显示    gtk_widget_show(window);    // 相当于让程序进入主循环,等待事件的发生    gtk_main();    return0;}

(iv): compiling GTK + programs

Of course, compiling is simpler and can be compiled using the GCC tool. But a tool is needed here, and that is Pkg-config, who will provide the required include files for automatic compilation. Well, then we'll use the following command to compile our program:

gcchello.c-ohello`pkg-config--libs--cflagsgtk+-2.0`

Note that the Pkg-config is quoted here as an anti-quote.

(v): Run the program

Once the compilation is complete, we can run our program directly using the following command:

./hello

In this way, the program runs successfully, so let's look at how it works:

(vi): written in the back

Instead of coveting, it is better to retreat and spin the nets.

My code has been uploaded to my github and everyone can download:
Gtkgame Source Download

Copyright NOTICE: Hello, reprint please leave my blog address, thank you

GTK re-pick--00

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.