我正在一个项目上,为此,我需要保存QR码的图像。但是,我需要能够覆盖旧图像,因为最初生成的QR码将保留其从中获取数据的字典的填充值,而其应显示的数据将不断变化。现在我的代码如下:
student = {
"firstName": "",
"middleName": "",
"lastName": "",
"studentID":"",
"homeRoom": ""}
###############
<QRScreen>:
on_enter:
root.on_start()
BoxLayout:
Button:
text: 'Return'
on_press: root.manager.current = 'main'
Image:
source: 'image.jpg'
###############
class QRScreen(Screen):
def on_start(self, *args):
KQR = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
KQR.add_data(student["studentID"])
KQR.make(fit=True)
img = KQR.make_image(fill_color="black", back_color="white")
img.save("image.jpg")
如果有人可以提供帮助,将不胜感激!