| CARVIEW |
Work with the language of your choice
Develop your GTK app with your language of choice by using Language Bindings or wrappers and take full advantage of the official GNOME bindings which guarantee API stability and time-based releases.
// Include gtk
#include <gtk/gtk.h>
static void on_activate (GtkApplication *app) {
// Create a new window
GtkWidget *window = gtk_application_window_new (app);
// Create a new button
GtkWidget *button = gtk_button_new_with_label ("Hello, World!");
// When the button is clicked, close the window passed as an argument
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_close), window);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
int main (int argc, char *argv[]) {
// Create a new application
GtkApplication *app = gtk_application_new ("com.example.GtkApplication",
G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}
imports.gi.versions['Gtk'] = '4.0';
const Gtk = imports.gi.Gtk;
// Create a new application
let app = new Gtk.Application({ application_id: 'com.example.GtkApplication' });
// When the application is launched…
app.connect('activate', () => {
// … create a new window …
let win = new Gtk.ApplicationWindow({ application: app });
// … with a button in it …
let btn = new Gtk.Button({ label: 'Hello, World!' });
// … which closes the window when clicked
btn.connect('clicked', () => { win.close(); });
win.set_child(btn);
win.present();
});
// Run the application
app.run([]);
#!/usr/bin/env perl
use strict; use warnings; use utf8;
use Glib::IO;
use Gtk4;
# Create a new application
my $app =
Gtk3::Application->new('com.example.Gtk3Application', 'G_APPLICATION_FLAGS_NONE');
# When the application is launched…
$app->signal_connect(
activate => sub {
my $app = shift;
# … create a new window …
my $win = Gtk3::ApplicationWindow->new($app);
# … with a button in it …
my $btn = Gtk3::Button->new('Hello World!');
# … which closes the window when clicked
$btn->signal_connect(clicked => sub { $win->close(); });
$win->set_child($btn);
$win->present();
}
);
# Run the application
$app->run(\@ARGV);
# Load Gtk
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
# When the application is launched…
def on_activate(app):
# … create a new window…
win = Gtk.ApplicationWindow(application=app)
# … with a button in it…
btn = Gtk.Button(label='Hello, World!')
# … which closes the window when clicked
btn.connect('clicked', lambda x: win.close())
win.set_child(btn)
win.present()
# Create a new application
app = Gtk.Application(application_id='com.example.GtkApplication')
app.connect('activate', on_activate)
# Run the application
app.run(None)
use glib::clone;
// glib and other dependencies are re-exported by the gtk crate
use gtk::glib;
use gtk::prelude::*;
// When the application is launched…
fn on_activate(application: >k::Application) {
// … create a new window …
let window = gtk::ApplicationWindow::new(application);
// … with a button in it …
let button = gtk::Button::with_label("Hello World!");
// … which closes the window when clicked
button.connect_clicked(clone!(@weak window => move |_| window.close()));
window.set_child(Some(&button));
window.present();
}
fn main() {
// Create a new application with the builder pattern
let app = gtk::Application::builder()
.application_id("com.github.gtk-rs.examples.basic")
.build();
app.connect_activate(on_activate);
// Run the application
app.run();
}
int main (string[] argv) {
// Create a new application
var app = new Gtk.Application ("com.example.GtkApplication",
GLib.ApplicationFlags.FLAGS_NONE);
app.activate.connect (() => {
// Create a new window
var window = new Gtk.ApplicationWindow (app);
// Create a new button
var button = new Gtk.Button.with_label ("Hello, World!");
// When the button is clicked, close the window
button.clicked.connect (() => {
window.close ();
});
window.set_child (button);
window.present ();
});
return app.run (argv);
}
A feature-rich development tool
GTK has all the features that a widget toolkit needs to have. These features make it the most trusted toolkit for developing Linux applications.
Portability
Projects built using GTK and its dependencies run on well known operating systems.
Stability
GTK delivers the enticing features and superb performance which adds to your applications.
Language Bindings
GTK is written in C but has been designed to support a wide range of languages such as Python, JavaScript, C++, Rust and many more.
Interfaces
GTK has a comprehensive collection of core widgets like Buttons, Windows, Toolbars for use in your application.
Open Source
GTK is a free and open-source project maintained by GNOME and an active community of contributors. GTK is released under the terms of the GNU Lesser General Public License.
API
GTK boasts of an easy to use API which helps in decreasing your development time and help you achieve better results.
Accommodation
GTK caters to many features like Native look and feel, theme support, Object-oriented approach that today’s developers look for in a toolkit.
Foundations
GTK is built on top of GLib. GLib provides the fundamental data types and system integration points to avoid duplicated code in applications.
Develop with GTK
By taking advantage of GTK being a cross-platform development tool and its easy to use API, you can develop amazing apps using the GTK. If you are interested in developing an app, get started now by developing this example application.
Develop GTK
GTK is a large project and relies on volunteers from around the world. To help us with the project development, hack away on the existing bugs and feature requests.
Looking for Help?
If you want to ask questions about GTK, whether it’s for developing applications with GTK or contributing to GTK itself, you can use the GNOME Discourse instance, under the Platform/Core category. You can use tags like gtk or glib to narrow down the topic of discussion to specific libraries. You can also ask questions in our Matrix room.
News and Events
Meet the community
As regularly as possible, GTK team meetings take place at conferences and hackfests to discuss the future of GTK and define a roadmap.
Contribute to GTK
If you are a developer and want to contribute to GTK, you are more than welcome to do so.