gtk3 Zelfstudie
Aan de slag met gtk3
Zoeken…
Opmerkingen
GTK + 3 ook bekend als Gtk3 is een multi-platform GUI toolkit, het is geschreven in C maar heeft bindingen voor veel talen, waaronder C ++, Python, Vala en Ruby. (Zie voor de volledige lijst de Gtk-website ).
Gtk + is onderdeel van het GNU-project en valt onder de GNU LGPL-licenties, wat betekent dat het mag worden gebruikt door alle ontwikkelaars, inclusief ontwikkelaars die eigen software ontwikkelen, zonder licentiekosten of royalty's.
Credits: losjes gebaseerd op http://www.gtk.org/
versies
Versie | Publicatiedatum |
---|---|
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 |
bronnen:
Installatie of instellingen
Python
ramen
De eenvoudigste manier om GTK3 voor Python te installeren is met behulp van PyGObject voor Windows . Het biedt een installatieprogramma dat de meeste dingen installeert die u nodig hebt om GTK-applicaties te ontwikkelen.
Het aantal opties dat het PyGObject-installatieprogramma biedt, kan ontmoedigend zijn, maar voor de meeste GTK-projecten is de enige optie die u moet selecteren GTK+ 3.xx
C ++
De C ++ binding voor Gtk + staat bekend als gtkmm .
ramen
Op Microsoft Windows kan gtkmm worden geïnstalleerd via een MSYS2- omgeving. Nadat de MSYS2-omgeving is ingesteld door het installatieprogramma te installeren en de pakketlijst bij te werken, installeert u gtkmm met
pacman -S mingw-w64-x86_64-gtkmm3 #64 bit
pacman -S mingw-w64-i686-gtkmm3 #32 bit
Installeer pkg-config voor eenvoudig verkrijgen van compiler- en linker-vlaggen en integratie van GNU autotools build
pacman -S pkg-config
Nu kan de gtkmm-toepassing worden gecompileerd, gekoppeld en uitgevoerd vanuit een MSYS2-omgeving.
# 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
Het uitvoerbare bestand wordt echter niet buiten de MSYS2-shell uitgevoerd vanwege het ontbreken van standaardomgevingsvariabelen voor het zoeken naar .dll. De volgende DLL-bestanden moeten handmatig worden gekopieerd van <MSYS2 INSTALLATION DIRECTORY>\mingw64\lib\
(voor 64-bits installatie) naar de applicatiemap (waar de .exe
zich bevindt). De versienummers kunnen veranderen afhankelijk van de installatie.
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
Na deze stap zou het programma moeten worden uitgevoerd. Maar het zal geen standaardpictogrammen vinden voor Gtk +, dwz het Adwaita-pictogramthema , dus pictogrammen worden mogelijk niet geladen. De pictogrammen en een paar andere bestanden moeten in de applicatiemap worden gekopieerd zodat de applicatie ze kan laden.
Van <MSYS2 INSTALL DIRECTORY>
mingw64
|
+-- lib
|
+-- gdk-pixbuf-2.0
share
|
+-- icons
|
+-- Adwaita
|
+-- hicolor (fallback icon theme for Gtk+)
Naar toepassingsmap, met dezelfde mapstructuur.
[C ++] "Hallo wereld" in 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] "Hallo wereld" in 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;
}
beginnerskit
#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;
}
compileren:
c++ starterkit.c `pkg-config --libs --cflags gtk+-3.0` -o p
en
./p