gtk3 Tutoriel
Démarrer avec gtk3
Recherche…
Remarques
GTK + 3, également connu sous le nom de Gtk3, est un toolkit d'interface graphique multi-plateforme, il est écrit en C mais contient des liaisons pour de nombreux langages, dont C ++, Python, Vala et Ruby. (Pour la liste complète, voir le site Web de Gtk ).
Gtk + fait partie du projet GNU et relève des licences GNU LGPL, ce qui signifie qu'il est autorisé à être utilisé par tous les développeurs, y compris ceux qui développent des logiciels propriétaires, sans droits de licence ni redevances.
Crédits: librement basés sur http://www.gtk.org/
Versions
Version | Date de sortie |
---|---|
3.20 | 2016-03-01 |
3.18 | 2015-09-01 |
3.16 | 2015-03-01 |
3.14 | 2014-09-01 |
3.12 | 2014-03-01 |
3.10 | 2013-09-01 |
3.8 | 2013-03-01 |
3.6 | 2012-09-01 |
3.4 | 2012-04-01 |
3.2 | 2011-10-01 |
3.0 | 2010-02-01 |
Sources:
Installation ou configuration
Python
les fenêtres
La méthode la plus simple pour installer GTK3 pour Python consiste à utiliser PyGObject pour Windows . Il offre un installateur qui installe la plupart des choses dont vous avez besoin pour développer des applications GTK.
Le nombre d'options offertes par l'installateur PyGObject peut être décourageant, mais pour la plupart des projets GTK, la seule option que vous devez sélectionner est GTK+ 3.xx
C ++
La liaison C ++ pour Gtk + est appelée gtkmm .
les fenêtres
Sur Microsoft Windows, gtkmm peut être installé via l'environnement MSYS2 . Une fois l'environnement MSYS2 configuré en installant le programme d'installation et en mettant à jour la liste des packages, installez gtkmm avec
pacman -S mingw-w64-x86_64-gtkmm3 #64 bit
pacman -S mingw-w64-i686-gtkmm3 #32 bit
Installez pkg-config pour obtenir facilement des drapeaux de compilateur et d'éditeur de liens et l'intégration de la génération d'autotools GNU
pacman -S pkg-config
Maintenant, l'application gtkmm peut être compilée, liée et exécutée dans l'environnement MSYS2.
# enable C++ 14 support if needed
# -mwindows flag is to suppress the background command-prompt window
# for GUI applications
g++ -mwindows -std=c++14 -o app.exe app.cpp `pkg-config --cflags --libs gtkmm-3.0`
./app.exe
Mais l'exécutable ne s'exécutera pas en dehors du shell MSYS2 en raison de l'absence de variables d'environnement standard pour la recherche .dll. Les fichiers .dll suivants doivent être copiés à partir de <MSYS2 INSTALLATION DIRECTORY>\mingw64\lib\
(pour une installation 64 bits) dans le répertoire de l' application (où se trouve le .exe
) manuellement. Les numéros de version peuvent changer en fonction de l'installation.
libatk-1.0-0.dll
libatkmm-1.6-1.dll
libbz2-1.dll
libcairo-2.dll
libcairo-gobject-2.dll
libcairomm-1.0-1.dll
libepoxy-0.dll
libexpat-1.dll
libffi-6.dll
libfontconfig-1.dll
libfreetype-6.dll
libgcc_s_seh-1.dll
libgdk_pixbuf-2.0-0.dll
libgdk-3-0.dll
libgdkmm-3.0-1.dll
libgio-2.0-0.dll
libgiomm-2.4-1.dll
libglib-2.0-0.dll
libglibmm-2.4-1.dll
libgmodule-2.0-0.dll
libgobject-2.0-0.dll
libgtk-3-0.dll
libgtkmm-3.0-1.dll
libharfbuzz-0.dll
libiconv-2.dll
libintl-8.dll
libpango-1.0-0.dll
libpangocairo-1.0-0.dll
libpangoft2-1.0-0.dll
libpangomm-1.4-1.dll
libpangowin32-1.0-0.dll
libpixman-1-0.dll
libpng16-16.dll
libsigc-2.0-0.dll
libstdc++-6.dll
libwinpthread-1.dll
zlib1.dll
Après cette étape, le programme doit être exécuté. Mais il ne trouvera pas d'icônes standard pour Gtk +, c'est-à-dire le thème de l'icône Adwaita , de sorte que les icônes ne seront pas chargées. Les icônes et quelques autres fichiers doivent être copiés dans le répertoire de l'application pour que l'application puisse les charger.
De <MSYS2 INSTALL DIRECTORY>
mingw64
|
+-- lib
|
+-- gdk-pixbuf-2.0
share
|
+-- icons
|
+-- Adwaita
|
+-- hicolor (fallback icon theme for Gtk+)
Vers le répertoire de l'application, avec la même structure de répertoire.
[C ++] "Hello World" en gtkmm
#include <gtkmm/application.h>
#include <gtkmm/applicationwindow.h>
#include <gtkmm/button.h>
// main window of the application
class HelloWorldWindow : public Gtk::ApplicationWindow {
// a simple push button
Gtk::Button btn;
public:
HelloWorldWindow()
: btn("Click me!") {// initialize button with a text label
// when user presses the button "clicked" signal is emitted
// connect an event handler for the signal with connect()
// which accepts lambda expression, among other things
btn.signal_clicked().connect(
[this]() {
btn.set_label("Hello World");
});
// add the push button to the window
add(btn);
// make the window visible
show_all();
}
};
int main(int argc, char *argv[]) {
// This creates an Gtk+ application with an unique application ID
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example.HelloApp");
HelloWorldWindow hw;
// this starts the application with our window
// close the window to terminate the application
return app->run(hw);
}
[C] "Hello World" dans Gtk +
#include <gtk/gtk.h>
// callback function which is called when button is clicked
static void on_button_clicked(GtkButton *btn, gpointer data) {
// change button label when it's clicked
gtk_button_set_label(btn, "Hello World");
}
// callback function which is called when application is first started
static void on_app_activate(GApplication *app, gpointer data) {
// create a new application window for the application
// GtkApplication is sub-class of GApplication
// downcast GApplication* to GtkApplication* with GTK_APPLICATION() macro
GtkWidget *window = gtk_application_window_new(GTK_APPLICATION(app));
// a simple push button
GtkWidget *btn = gtk_button_new_with_label("Click Me!");
// connect the event-handler for "clicked" signal of button
g_signal_connect(btn, "clicked", G_CALLBACK(on_button_clicked), NULL);
// add the button to the window
gtk_container_add(GTK_CONTAINER(window), btn);
// display the window
gtk_widget_show_all(GTK_WIDGET(window));
}
int main(int argc, char *argv[]) {
// create new GtkApplication with an unique application ID
GtkApplication *app = gtk_application_new(
"org.gtkmm.example.HelloApp",
G_APPLICATION_FLAGS_NONE
);
// connect the event-handler for "activate" signal of GApplication
// G_CALLBACK() macro is used to cast the callback function pointer
// to generic void pointer
g_signal_connect(app, "activate", G_CALLBACK(on_app_activate), NULL);
// start the application, terminate by closing the window
// GtkApplication* is upcast to GApplication* with G_APPLICATION() macro
int status = g_application_run(G_APPLICATION(app), argc, argv);
// deallocate the application object
g_object_unref(app);
return status;
}
kit de démarrage
#include <gtk/gtk.h>
static void destroy(GtkWidget *widget, gpointer data)
{
gtk_main_quit();
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Window");
g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
GtkWidget *k;
k= gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window), k);
GtkWidget* la,*r;
la = gtk_button_new_with_label (",mkl");
gtk_fixed_put (GTK_FIXED (k), la,50,237);
gtk_widget_set_size_request(la, 98, 90);
// gtk_container_set_border_width(GTK_CONTAINER (la) , 5);
r = gtk_button_new_with_label (",kii");
gtk_fixed_put (GTK_FIXED (k), r,150,237);
gtk_widget_set_size_request(r, 98, 90);
gtk_widget_set_size_request(GTK_WIDGET(window),300,349);
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
compiler:
c++ starterkit.c `pkg-config --libs --cflags gtk+-3.0` -o p
et
./p