Gtk.Picture takes up horizontal space that it doesn't need

I am trying to create a gallery of images using Gtk.Picture inside a Adw.WrapBox. I want each image to only take as much space as i set with set_size_request , without taking all the horizontal space unnecessarily,
For example, the button widgets within a wrapbox look like this:

button=Gtk.Button(label="Some"+str(random.random()*100))

self.wrapbox.append(button)

But this is what images do within the same thing, the only way I found to constrict the width is via clamps, but that prevents it from expanding at all if I want to expand it later on,


This is a better view of whats happening when I put the Gtk.Picture within a Gtk.Button

This prevents it from working properly within both a wrapbox and flowbox, where I have to use clamps but using that no longer makes the JustifyMode.FILL behavior work, as it needs the children to expandable.

Please point me to the right direction.


from gi.repository import Adw
from gi.repository import Gtk, Gio
import random

class GalleryviewWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'GalleryviewWindow'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        scrollingView = Gtk.ScrolledWindow()

        spacing = 12

        self.wrapbox = Adw.WrapBox(
            justify=Adw.JustifyMode.FILL,
            child_spacing=spacing,
            line_spacing=spacing,
            margin_top=12,
            margin_bottom=12,
            margin_start=12,
            margin_end=12,
        )

        scrollingView.set_child(self.wrapbox)

        directory_path = '/home/riyani/Downloads/zips/sample-images-main/docs/'

        pictures = [x.get_name() for x in Gio.file_new_for_path(directory_path).enumerate_children('standard::name,standard::content-type', Gio.FileQueryInfoFlags.NONE, None) if x.get_content_type().startswith('image')]

        for i in range(25):

            pictureFile = Gio.File.new_for_path(directory_path+pictures[i])
            pictureWidget = Gtk.Picture.new_for_file(pictureFile)
            paintable = pictureWidget.get_paintable()
            height = paintable.get_height()
            width = paintable.get_width()
            ratio = width/height;
            print(ratio)
            button=Gtk.Button()

            button.set_size_request(height/4, width/4)


            self.wrapbox.append(button)


        self.set_content(scrollingView)
        self.set_default_size(1000, 600)
        

Screencast From 2026-01-12 20-56-40


from gi.repository import Adw
from gi.repository import Gtk, Gio
import random

class GalleryviewWindow(Adw.ApplicationWindow):
    __gtype_name__ = 'GalleryviewWindow'

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        scrollingView = Gtk.ScrolledWindow()

        spacing = 12

        self.wrapbox = Adw.WrapBox(
            justify=Adw.JustifyMode.FILL,
            child_spacing=spacing,
            line_spacing=spacing,
            margin_top=12,
            margin_bottom=12,
            margin_start=12,
            margin_end=12,
        )

        scrollingView.set_child(self.wrapbox)

        directory_path = '/home/riyani/Downloads/zips/sample-images-main/docs/'

        pictures = [x.get_name() for x in Gio.file_new_for_path(directory_path).enumerate_children('standard::name,standard::content-type', Gio.FileQueryInfoFlags.NONE, None) if x.get_content_type().startswith('image')]

        for i in range(25):

            pictureFile = Gio.File.new_for_path(directory_path+pictures[i])
            pictureWidget = Gtk.Picture.new_for_file(pictureFile)
            paintable = pictureWidget.get_paintable()
            height = paintable.get_height()
            width = paintable.get_width()
            ratio = width/height;
            print(ratio)
            button=Gtk.Button()

            pictureWidget.set_size_request(height/4, width/4)


            self.wrapbox.append(pictureWidget)


        self.set_content(scrollingView)
        self.set_default_size(1000, 600)
        

Screencast From 2026-01-12 20-57-07