I'm trying to convert a json file into a qr code using pyqrcode
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()
Here is an example of JSON file:
[
{
"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": ""
}
]
When I try to run the code it gives to me this error: "TclError: bad option "-mode": must be -confirmoverwrite, -defaultextension, -filetypes, -initialdir, -initialfile, -parent, -title, or -typevariable"
How can I solve it? Thanks in advance.