python - 如何在 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中使用多个图像进行多项选择?任何人都可以在此代码中提供帮助吗?
解决方案
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')
推荐阅读
- c# - 我如何获得消息中提到的 Discord 成员并授予他角色?
- python - 在 for 循环中迭代 Python 中 Seaborn kdeplot 中的颜色
- javascript - 编写不和谐机器人时的权限问题
- javascript - React:如何仅渲染可见元素
- php - 如何将与 php 中的 html 表单中的字符串相同的图像发送到服务器或作为对 API 的请求
- android - 在颤振中使用流生成器时,我不断收到轻微的空错误
- javascript - 如何将不可点击的纯文本 URL 转换为 HTML 源中的链接
- javascript - 编写高尔夫代码比基本代码更干净
- flutter - 嵌套流构建器以从云 Firestore 获取数据
- python - 使用 MYSQL 查询查询数据库时,SQL Alchemy 非常缓慢