i have a problem with this code
it is working good in pycharm but cannot convert it to exe
when i convert it not open or have a problem
can you help me please
this is my code
import openpyxl
from barcode import Code128
from barcode.writer import ImageWriter
from PIL import Image, ImageDraw, ImageFont
from arabic_reshaper import arabic_reshaper
from bidi.algorithm import get_display
import textwrap
import subprocess
import win32print
import os
Determine the main file path
main_file_path = os.path.join(os.path.expanduser(“~”), “PycharmProjects”, “BarCode”, “testbarcode1.xlsx”)
while True:
# Receive data from the user
data = input(" S c a n : ")
if data.lower() == “exit”:
print(“Exiting program…”)
break
try:
number = int(input(" Quantity : "))
except ValueError:
print("Invalid input. Please try again.")
continue
# Read the main file
main_workbook = openpyxl.load_workbook(main_file_path)
main_sheet = main_workbook.active
# Search for the data in the main file and copy it to the print file
found = False
for row in main_sheet.iter_rows(values_only=True):
if str(data) in map(str, row):
print(row)
found = True
# Create a barcode for the data
barcode_value = data
barcode = Code128(barcode_value, writer=ImageWriter())
# Save the barcode as an image
barcode_file_path = os.path.join(os.path.expanduser("~"), "PycharmProjects", "BarCode", f"barcode_{barcode_value}.png")
barcode.save(barcode_file_path)
# Create the barcode image
barcode_image = barcode.render()
barcode_image = barcode_image.resize((200, 100))
# Create an image containing the numerical value
font = ImageFont.truetype('arial.ttf', size=50)
data_image = Image.new('RGB', (500, 50), color='white')
data_image_draw = ImageDraw.Draw(data_image)
data_image_draw.text((50, 1), str(number), fill='black', font=font, align="center")
# Add the value of column B
font_b = ImageFont.truetype('arial.ttf', size=14)
column_b_text = f"{row[1]}"
reshaped_text = arabic_reshaper.reshape(column_b_text)
bidi_text = get_display(reshaped_text)
max_width = 40 # Set the maximum width of each line
wrapped_text = textwrap.wrap(bidi_text, width=max_width)
column_b_text = '\n'.join(wrapped_text)
column_b_image = Image.new('RGB', (200, 50), color='white')
column_b_image_draw = ImageDraw.Draw(column_b_image)
column_b_image_draw.text((0, 0), column_b_text, fill='black', font=font_b, align="center")
# Desired size of the final image
desired_width = 500
desired_height = 400
# Create the composite image
merged_image = Image.new('RGB', (200, barcode_image.height + data_image.height + column_b_image.height))
merged_image.paste(barcode_image, (0, 0))
merged_image.paste(data_image, (0, barcode_image.height))
merged_image.paste(column_b_image, (0, barcode_image.height + data_image.height))
# Resize the final image
merged_image = merged_image.resize((desired_width, desired_height), resample=Image.LANCZOS)
# Save the final image
final_image_path = os.path.join(os.path.expanduser("~"), "PycharmProjects", "BarCode", f"final_image_{data}.png")
merged_image.save(final_image_path)
# Get the default printer name
default_printer = win32print.GetDefaultPrinter()
# Print the final composite image on the default printer
subprocess.call(['mspaint', '/p', final_image_path, default_printer])
break # Exit the loop after finding the data
# Check if the data is not found
if not found:
print("Data not found in the main file.")