我正在尝试使用pyqrcode将json文件转换为qr码
import tkinter as tk
from tkinter import filedialog
import json
import pyqrcode as qrcode
root= tk.Tk()
root.title('Convertitore CSV in JSON')
canvas1 = tk.Canvas(root, width = 300, height = 300, bg = 'lightsteelblue2', relief = 'raised')
canvas1.pack()
label1 = tk.Label(root, text='Tool Conversione File', bg = 'lightsteelblue2')
label1.config(font=('helvetica', 20))
canvas1.create_window(150, 60, window=label1)
def json_to_qrcode(jsonFilePath2, imageFilePath):
with open(jsonFilePath2, 'w', encoding='utf-8') as jsonf:
jsonReader = json.load(jsonf)
qr = qrcode.QRCode(version = 1, box_size = 15, border = 5)
data = jsonReader
qr.add_data(data)
qr.make(fit = True)
img = qr.make_image(fill = 'black', back_color = 'white')
img.save('Dieta.png')
jsonFilePath2 = filedialog.askopenfilename()
imageFilePath = filedialog.asksaveasfilename(mode='w', defaultextension=".png")
browseButton_CSV = tk.Button(text=" Importa JSON File ", command=json_to_qrcode(jsonFilePath2, imageFilePath), bg='green', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(150, 130, window=browseButton_CSV)
root.mainloop()
以下是JSON文件的一个示例:
[
{
"Giorno": "Lunedi",
"Tipologia": "Prima Colazione",
"Alimento": "Fette biscottate",
"Quantita": "3",
"UDM": "fette",
"Note": ""
},
{
"Giorno": "Lunedi",
"Tipologia": "Prima Colazione",
"Alimento": "Latte",
"Quantita": "200",
"UDM": "g",
"Note": ""
}
]
当我尝试运行它给我的代码时,会出现以下错误:“TclError:bad option”-mode”:必须是-confirmoverwrite,-defaultextension,-filetypes,-initialdir,-initialfile,-parent,-title或-typevariable
我怎样才能解决它? 提前谢谢
你能试试下面的代码吗。我认为你的问题现在应该解决了
请安装枕头库。(pip安装枕)
问题
您试图为filedialog.asksaveasfilename()函数传递错误的参数
您正在使用pyqrcode而不是qrcode。(您已经编写了有关qrcode库的代码)
相关问题 更多 >
编程相关推荐