I can't add Gtk.Image to Gtk.GridView (python&gtk4)

grid = Gtk.GridView()

class NM(GObject.Object):
name = GObject.Property(type=str)
def init(self, name):
super().init()
self.name = name

ls = Gio.ListStore()
for i in range(20):
ls.append(NM(i))
ss = Gtk.SingleSelection()
ss.set_model(ls)
grid.set_model(ss)
factory = Gtk.SignalListItemFactory()

def f_setup(fact, item):
img = Gtk.Image()
img.set_selectable(False)
item.set_child(img)
factory.connect(“setup”, f_setup)

def f_bind(fact, item):
item.get_child().set_from_file(“file.png”)
factory.connect(“bind”, f_bind)

grid.set_factory(factory)

First of all, this code is incomprehensible and incomplete. Please use the forum’s code formatting tool and include a minimum working example, if possible, include information such as error messages too.

That said, Gtk.Image does not have a set_selectable() method.

1 Like

I don’t know how to secure the code
Sorry

I took this example:
GTK4PythonTutorial/part1.py at main · Taiko2k/GTK4PythonTutorial · GitHub
and replaced Gtk.Label with a Gtk.Image

You cannot take a widget and replace it randomly with another one: different classes have different methods.

1 Like

Okay, if you’re learning, which is what it seems like, I recommend starting here.

There are several basic concepts that you need to understand to be able to use Gtk correctly.

I know the amount of initial information and the forum can be a little intimidating, but you’re welcome and feel free to ask questions.

1 Like