0
import qrcode
import time
import tkinter as tk
import os
import shutil
from sys import exit

# GUI with tkinter

root = tk.Tk()
root.title('Window')
root.geometry("400x400+50+50")
root.iconbitmap('QRCODE-GENERATOR.ico')
root.configure(bg="grey")

lbl_1 = tk.Label(root, text="Qrcode generator", font="1")
entry_1 = tk.Entry(root)



lbl_1.pack()
entry_1.pack(side=tk.RIGHT)



tk.mainloop()

# GUI end

if not entry_1:
    exit()

data = entry_1

# Qr code setup

qr = qrcode.QRCode(
    version=1,
    box_size=5,
    border=5
)


# Adding the data to the system



qr.add_data(data)

# qr customizing
qr.make(fit=True)
img = qr.make_image(
    fill_color= 'black',
    back_color= 'white'
)

time.sleep(2)
# saving qr
img.save('output.png')



# absolute path
src_path = r"D:\Python\QRcode generator\output.png"
dst_path = r"D:\Users"

shutil.move(src_path, dst_path)

you see I'm getting the error file already exists, so what I want it to add a number to the QR code every time someone saves it. So it doesn't throw the error, you see python and shutils just gets confused when saving a file with the same name 2 times. If you don't really get what I'm saying then just tell me to make some edits, ill make it simpler.

Note: I might not be able to respond when you answer

2 Answers2

0

Based on what i understand you want to add something at the end of the name file to prevent throwing an error.

import time
FILE_NAME = f"output-{time.time()}.png"
img.save(FILE_NAME)
mango orange
  • 118
  • 9
0

Try this:

  1. Put all your code into a while true loop.

  2. Declare a variable "num" and assign it to the integer 0. MAKE SURE THIS IS OUTSIDE THE WHILE TRUE LOOP!

  3. Change your code so that this part: src_path = r"D:\Python\QRcode generator\output.png" dst_path = r"D:\Users"

    looks like this:

    src_path = r"D:\Python\QRcode generator\output" + str(num) + ".png" dst_path = r"D:\Users"

num += 1

(note) If you close the program it will reset

Bozzyma
  • 5
  • 2