GTK and Python

About

PyGObject is a Python package which provides bindings for GObject based libraries such as GTK, GStreamer, WebKitGTK, GLib, GIO and many more.

It supports Linux, Windows, and macOS and works with Python 3.8+ and PyPy3. PyGObject, including this documentation, is licensed under the LGPLv2.1+.

If you want to write a Python application for GNOME or a Python GUI application using GTK, then PyGObject is the way to go. For tutorials please see the PyGObject Guide and reference the GNOME Python API Docs.

For more information, visit the PyGObject Docs.

PyGObject API

You can view the API Reference for the PyGObject at the GNOME Python API Docs.

A Hello World app

Below is an Hello World program that can be used as an example to get started with the PyGObject.

import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk

def on_activate(app):
    win = Gtk.ApplicationWindow(application=app)
    btn = Gtk.Button(label="Hello, World!")
    btn.connect('clicked', lambda x: win.close())
    win.set_child(btn)
    win.present()

app = Gtk.Application(application_id='org.gtk.Example')
app.connect('activate', on_activate)
app.run(None)

Explanation

gi python module is imported to use APIs linked with the PyGObject.

Contribute

If you are interested in contributing to the PyGObject project or want to get in touch with the original source files, you can visit the project’s git repository on Gitlab.

See More

Observed a typo or some missing information, edit this page.
Read on how to contribute to this website.