GTK4 PyGObject testing?

Is there an easy way to start testing/playing around with new features with python applications for gtk4? I’m using Fedora 32 with gtk4 package installed. Do I need to grab a specific branch of pygobject? Any instructions out there or link to help?

1 Like

You can already use GTK4 from Python:

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

The main issue is that PyGObject has a bunch of overrides for GTK2 and GTK3 to make the API more “Pythonic”, and currently there are no overrides for GTK4.

2 Likes

I get the following error doing that

Traceback (most recent call last):
File "example.py", line 3, in <module>
from gi.repository import Gtk
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
File "/usr/lib64/python3.8/site-packages/gi/importer.py", line 146, in load_module
dynamic_module = load_overrides(introspection_module)
File "/usr/lib64/python3.8/site-packages/gi/overrides/__init__.py", line 118, in load_overrides
override_mod = importlib.import_module(override_package_name)
File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/lib64/python3.8/site-packages/gi/overrides/Gtk.py", line 173, in <module>
class Container(Gtk.Container, Widget):
File "/usr/lib64/python3.8/site-packages/gi/module.py", line 131, in __getattr__
raise AttributeError("%r object has no attribute %r" % (
AttributeError: 'gi.repository.Gtk' object has no attribute 'Container'

I have gtk4-3.98.4-1.fc32.x86_64 and gtk4-devel-3.98.4-1.fc32.x86_64 installed.

You probably need pygobject from the main development branch.

In any case, this is the issue with the overrides, which needs to be fixed in pygobject.

Edited to add: there are various open merge requests about GTK4 updates:

1 Like