Importing GtkBuilder

After 6 months away from trying to write something with GTK4 and Python I thought I’d do some more.

I tried creating an AdwExpanderRow and using it as a template and I almost cried. I’ve got 7 templates in my code so I knew how to do it… I’m back at the bottom of the learning curve.

So I gave up and thought I’d try GtkBuilder. I can’t even import it!

import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Gtk, Adw, Gio, GObject, GtkBuilder
ImportError: cannot import name GtkBuilder, introspection typelib not found
(.venv) dave@opensusetumbleweed:~/Projects/Books> pip list
Package    Version
---------- -------
pip        25.0
pycairo    1.26.1
PyGObject  3.48.2
setuptools 65.5.0

I clearly missing something but what?? I’ve never had a problem in the past with GtkBuilder.

Thank you for any help.

GtkBuilder is a class, part of the Gtk namespace: you don’t import it, you import Gtk and use Gtk.Builder like you would with a Gtk.Button.

You also likely don’t want to use GtkBuilder directly: use a widget template.

Well, that’s all of embarrassing, a sign I need a break and a good example of how Copilot can be dreadful! Enabled it yesterday, disabling today!

Thank you!

I hoped to exclusively use widget templates but after not looking Python for 6 months I can’t even read my own code! That ExpanderRow has a ColumnView on which I want to fill with sql data. For today, I need to keep it simple! 1.5 days trying to get the widget template to work. 5 mins getting GtkBuilder to work, once I knew I didn’t have import it!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.