1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| from barcode import EAN13
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import random, os
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
row1 = 1
row2 = 2
column1 = 0
def codebarre(event):
global row1, row2, column1
num = random.randint(1,9999999999999)
ean = EAN13(f'{num:013}')
name = entry.get()
if os.path.exists(name+'.svg') or not name:
entry.configure(bg="RED")
entry.update_idletasks()
root.after(500)
entry.configure(bg="WHITE")
return
ean.save(name)
label2 = tk.Label(root, text=name+".svg")
label2.grid(row=row1, column=column1, columnspan=2)
path=name+'.png'
drawing = svg2rlg(name+".svg")
renderPM.drawToFile(drawing, path, fmt="PNG")
image = Image.open(path)
imagetk = ImageTk.PhotoImage(image)
label3 = tk.Label(root, image=imagetk)
label3.image = imagetk
label3.grid(row=row2, column=column1, columnspan=2)
ttk.Separator(root, orient='horizontal').grid(row=row2+1, column=column1, columnspan=2, pady=5, ipadx=120)
os.remove(path)
entry.delete(0,tk.END)
row1, row2 = row1+3, row2+3
if row1%16==0:
column1+=3
row1=1
row2=2
def changeBTtext():
button2.configure(text=f"Générer {spinbox.get()} CB")
root = tk.Tk()
label = tk.Label(root, text = "NOM :")
label.grid(row=0, column=0, padx=5, pady=5)
entry = tk.Entry(root, width=20)
entry.grid(row=0, column=1, padx=5)
entry.focus_set()
entry.bind("<Return>", codebarre)
root.mainloop() |
Partager