-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |