如何在kivy中制作画廊?

How to make gallery in kivy?

我想去基维的这个画廊how to make gallery view How to add this kivy then is showing many display and carousel in gallery? 有人可以帮忙吗?

class Gallery(Screen):
        pass 

.kv

<MyTile@SmartTile>:
        size_hint_y: None
        height: "240dp"
    
<Gallery>
    ScrollView:
        MDGridLayout:
            cols: 3
            row_default_height: (self.width - self.cols*self.spacing[0]) / self.cols
            row_force_default: True
            adaptive_height: True
            padding: dp(4), dp(4)
            spacing: dp(4)
            MyTile:
                source:'*.jpg'

https://i.stack.imgur.com/loupw.png

这里有问题..

[ WARN:1] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\videoio\src\cap_msmf.cpp (376) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): OnReadSample() is called with error status: -1072873821
[ WARN:1] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\videoio\src\cap_msmf.cpp (388) `anonymous-namespace'::SourceReaderCB::OnReadSample videoio(MSMF): async ReadSample() call is failed with error status: -1072873821
[INFO   ] [Loader      ] using a thread pool of 2 workers
[ERROR  ] [AsyncImage  ] Not found <*.jpg>
[INFO   ] [Base        ] Start application main loop
[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback

这是画廊,但这里没有显示任何图片。任何人都可以告诉这段代码代码中的问题是什么?

我画了一个画廊的例子,我想这就是你想要的。

from kivymd.app import MDApp

from kivy.metrics import dp
from kivy.lang.builder import Builder
from kivy.uix.boxlayout import BoxLayout

import os

KV = """
<ImageButton@ButtonBehavior+FitImage>

<ImageManager>
    path: ""
    orientation: "vertical"
    size_hint_y: None
    height: root.height
    padding: dp(10)

    ImageButton:
        source: root.path
        
BoxLayout:
    RecycleView:
        id: rv
        key_viewclass: "viewclass"
        RecycleGridLayout:
            padding: dp(2)
            cols: 3
            default_size: None, dp(48)
            default_size_hint: 1, None
            size_hint_y: None
            height: self.minimum_height
"""


class ImageManager(BoxLayout):
    pass


class GalleryApp(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        self.manager_list = []
        self.dir = os.getcwd()
        self.available_image_format = ['.png', '.jpg', '.jpeg', '.bmp']  # etc

    def build(self):
        return Builder.load_string(KV)

    def on_start(self):
        self.load_images()

    def load_images(self):
        if not self.manager_list:
            for image in os.listdir(self.dir):
                target_filename, target_file_extension = os.path.splitext(image)
                if target_file_extension in self.available_image_format:
                    path_to_image = os.path.join(self.dir, image)
                    self.manager_list.append(
                        {
                            "viewclass": "ImageManager",
                            "path": path_to_image,
                            "height": dp(200),
                        }
                    )
            self.root.ids.rv.data = self.manager_list


GalleryApp().run()