E D R , A S I H C RSS

GTK+

What is GTK+?

GTK+ is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off projects to complete application suites.

GTK+ is free software and part of the GNU Project. However, the licensing terms for GTK+, the GNU LGPL, allow it to be used by all developers, including those developing proprietary software, without any license fees or royalties.

GTK+ is based on three libraries developed by the GTK+ team:
GLib is the low-level core library that forms the basis of GTK+ and GNOME. It provides data structure handling for C, portability wrappers, and interfaces for such runtime functionality as an event loop, threads, dynamic loading, and an object system.
Pango is a library for layout and rendering of text, with an emphasis on internationalization. It forms the core of text and font handling for GTK+-2.0.
The ATK library provides a set of interfaces for accessibility. By supporting the ATK interfaces, an application or toolkit can be used with such tools as screen readers, magnifiers, and alternative input devices.

GTK+ has been designed from the ground up to support a range of languages, not only C/C++. Using GTK+ from languages such as Perl and Python (especially in combination with the Glade GUI builder) provides an effective method of rapid application development.
- quoted from http://gtk.org

Hello world program with GTK+

  • 우선 GTK+ 라이브러리가 필요하다. Hello, World라는 버튼이 있고 이 버튼을 누르면 콘솔에 Hello, World를 찍고 윈도우를 종료시키는 간단한 예제

#include <gtk/gtk.h>

static void hello(GtkWidget *widget, gpointer data)
{
        g_print("Hello, World!!\n");
}

static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
        g_print("delete event occurred\n");
        return TRUE;
}

static void destroy(GtkWidget *widget, gpointer data)
{
        gtk_main_quit();
}

int main(int argc, char* argv[])
{
        GtkWidget *window;
        GtkWidget *button;

        gtk_init(&argc, &argv);

        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL);
        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);

        gtk_container_set_border_width(GTK_CONTAINER(window), 10);
        button = gtk_button_new_with_label("Hello World");

        g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(hello), NULL);
        g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy), G_OBJECT(window));

        gtk_container_add(GTK_CONTAINER(window), button);
        gtk_widget_show(button);
        gtk_widget_show(window);

        gtk_main();

        return 0;
}

컴파일을 하기 위해서는 gcc 명령행에 몇가지 파라메터를 더 주어야 한다. 아래는 한 예.
gcc hello.c -o hello `pkg-config --cflags --libs gtk+-2.0`
오오 이제 윈도우가 뜨는구나!!
----
프로그래밍분류
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:18
Processing time 0.0140 sec