From f60c38dcd2acf8eb5dad181043f47917cbf99543 Mon Sep 17 00:00:00 2001 From: Alay Sharma <87763921+mrvenom17@users.noreply.github.com> Date: Sat, 19 Oct 2024 13:50:37 +0530 Subject: [PATCH] added barcode generator --- Barcode_gen/barcode_generator.py | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Barcode_gen/barcode_generator.py diff --git a/Barcode_gen/barcode_generator.py b/Barcode_gen/barcode_generator.py new file mode 100644 index 00000000..6aaf3f88 --- /dev/null +++ b/Barcode_gen/barcode_generator.py @@ -0,0 +1,37 @@ +import barcode +from barcode.writer import ImageWriter +from tkinter import * +from tkinter import ttk +from tkinter import messagebox + +def generate_barcode(): + try: + ean = ean_entry.get() + if not ean.isdigit(): + messagebox.showerror("Error", "EAN must be a number.") + return + + # Generate barcode + my_code = barcode.EAN13(ean, writer=ImageWriter()) + my_code.save("barcode") + + # Display success message + messagebox.showinfo("Success", "Barcode generated successfully!") + except Exception as e: + messagebox.showerror("Error", f"An error occurred: {e}") + +# Create main window +root = Tk() +root.title("Barcode Generator") + +# EAN label and entry +ean_label = Label(root, text="Enter EAN:") +ean_label.grid(row=0, column=0, padx=10, pady=10) +ean_entry = Entry(root) +ean_entry.grid(row=0, column=1, padx=10, pady=10) + +# Generate button +generate_button = Button(root, text="Generate Barcode", command=generate_barcode) +generate_button.grid(row=1, column=0, columnspan=2, padx=10, pady=10) + +root.mainloop() \ No newline at end of file