首页 > 解决方案 > 如何在 Kivy 中使用 fileChooser 选择多个文件?

问题描述

.py:

class file(Popup):
    load = ObjectProperty()

class file1(Screen):
    file_path = StringProperty(None)
    the_popup = ObjectProperty(None)
    
    def select_to(self):
        self.the_popup= file(load=self.load)
        self.the_popup.open()
    def load(self, selection):
        pdf= FPDF()
        self.file_path = str(selection[0])
        self.the_popup.dismiss()
        imgs=[]
        imgs.append(self.file_path)
        for image in imgs:
            width, height= 0,0 
            pdf.add_page()
            pdf.image(image,0,0,width,height)
        pdf.save('name.pdf')

.kv

<file>
    title: "Choose a .jpg File"
    BoxLayout:
        orientation:"vertical"
        FileChooserIconView:
            id:filechooser
            multiselect: True
        BoxLayout:
            spacing: 20
            Button:
                text: "Cancel"
                on_release: root.dismiss()
            Button:
                text: "Load"
                on_release: root.load(filechooser.selection)             
<file1>
        BoxLayout:
            orientation:'vertical'
            Button:
                on_release: root.select_to()

我有问题如何在一个pdf中使用多个图像进行多项选择?任何人都可以在此代码中提供帮助吗?

标签: pythonimagepdfkivyfilechooser

解决方案


def load(self, selection):
        pdf= FPDF()
        self.file_path = str(selection[0])
        self.the_popup.dismiss()
        imgs=[]
        imgs.append(self.file_path)
        for image in selection:
            width, height= 0,0 
            pdf.add_page()
            pdf.image(image,0,0,width,height)
        pdf.save('name.pdf')

推荐阅读