GTK: Widgets, Signals & Layout
GTK is a free, open-source, cross-platform toolkit for building graphical user interfaces -- widely used on Linux (underlying the GNOME desktop environment) but also available on Windows and macOS. Written in C, with extensive bindings for Python (PyGObject), Rust, C++, and other languages.
Widgets: The Building Blocks
Any visible UI element -- a button, a label, a text entry, even a window itself -- is a widget. Complex interfaces are built by nesting simpler widgets: a window contains a layout container, which contains individual content widgets.
Signals: Event Handling
// A widget emits a signal (like "clicked") when an event occurs;
// application code connects a callback to respond
g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), NULL);
static void on_button_clicked(GtkWidget *widget, gpointer data) {
g_print("Button clicked!\n");
}Python via PyGObject
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk
def on_clicked(button):
print('Button clicked!')
window = Gtk.ApplicationWindow()
button = Gtk.Button(label='Click me')
button.connect('clicked', on_clicked)
window.set_child(button)Layout Containers
GtkBox -- arranges children in a single row or column.
GtkGrid -- arranges children into a configurable rows/columns structure, useful for aligning form labels with their inputs.
Containers organize how other widgets are positioned; they don't display content themselves.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free