目录
gtk概述
GTK是一个小部件工具包。由GTK创建的每个用户界面都由小部件组成。这是在C中使用GObject实现的,这是一个面向对象的C框架。[]小部件被组织在一个层次结构中。窗口小部件是主容器。然后,通过向窗口中添加按钮、下拉菜单、输入字段和其他小部件来构建用户界面。
GTK是由事件驱动的。该工具包侦听事件,如单击按钮,并将事件传递给应用程序。
hello,world
#include <iostream>
#include <gtk/gtk.h>
using namespace std;
static void
print_hello (GtkWidget *widget,
gpointer data)
{
cout<<"Hello World\n"<<endl;
}
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *button;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
button = gtk_button_new_with_label ("Hello World");
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
# g++ $(pkg-config --cflags gtk4) -o helloworld example-1.cpp $(pkg-config --libs gtk4)
./helloworld