Overview

PyGObject 3.42, released on March 20, 2022, adds GTK 4 support for modern GNOME applications in Python.

Main Features

GTK 4 support

PyGObject 3.42 supports GTK 4 with its new rendering model, event controllers, and modernized widgets.

python
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk

class MyApp(Gtk.Application):
    def do_activate(self):
        window = Gtk.ApplicationWindow(application=self)
        window.set_title('GTK 4 with PyGObject')
        label = Gtk.Label(label='Hello GTK 4!')
        window.set_child(label)
        window.present()

# app = MyApp()
# app.run()

Event controllers

GTK 4 replaces widget signals with event controllers for finer-grained user interaction handling.

python
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk

button = Gtk.Button(label='Click')

# GTK 4 click controller
gesture = Gtk.GestureClick()
gesture.connect('pressed', lambda g, n, x, y: print('Clicked!'))
button.add_controller(gesture)

Sources