Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions Barcode Generator/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
from barcode import EAN13
from barcode.writer import ImageWriter
import re

number = '5901234123457'
my_code = EAN13(number, writer=ImageWriter())
my_code.save('new_code 1')
def generate_barcode():
# Accept user input for the barcode number
number = input("Enter a 13-digit EAN-13 barcode number: ")

# Validate the input
if not re.match(r'^\d{13}$', number):
print("Invalid input. Please enter exactly 13 digits.")
return

# Accept user input for the file name
file_name = input("Enter the file name to save the barcode: ")

# Generate the barcode
my_code = EAN13(number, writer=ImageWriter())

# Customize the barcode appearance
options = {
'module_width': 0.2, # Width of each module
'module_height': 15.0, # Height of each module
'font_size': 10, # Font size for the text
'text_distance': 1.0, # Distance between the text and the barcode
'background': 'white', # Background color
'foreground': 'black', # Foreground color
'write_text': True, # Include the text below the barcode
}

# Save the barcode
my_code.save(file_name, options=options)
print(f"Barcode saved as {file_name}.png")

if __name__ == "__main__":
generate_barcode()