0

I am programming a new python file which i need to convert it to .exe , it contains many images which i use PIL to open and resize them, then i add them to different labels , the directory is "F://image.png" , So after i convert it if another pc not containing the drive (F) and also not containing all images on it , exe will not run .. is there any solution to add them to the -.py- file to solve this . i can change the directory to C: but I think it is not a good solution, as i have to copy all the images to a folder after i convert -py- file.

resized_on=on.resize((60 , 30) , Image.ANTIALIAS)
on_new=ImageTk.PhotoImage(resized_on)

off = Image.open("F://off.png")
resized_off=off.resize((60 , 30 ) , Image.ANTIALIAS)
off_new=ImageTk.PhotoImage(resized_off)
  
show_img=Image.open('F://show1.png')
show_res=show_img.resize((50 , 50))
result_img=ImageTk.PhotoImage(show_res)

dose_img=Image.open('F://dose.png')
dose_resized=dose_img.resize((50 , 50))
dose_final=ImageTk.PhotoImage(dose_resized)

power_img=Image.open('F://power.png')
power_res=power_img.resize((50 , 50))
power_final=ImageTk.PhotoImage(power_res) ```
    
    
  • I would suggest you store the images in the same directory as your python script, and pack the images when using PyInstaller with the [`--add-data` switch](https://pyinstaller.org/en/stable/usage.html#cmdoption-add-data). – GordonAitchJay Aug 24 '22 at 08:12
  • I have to change the directory in python script , because if i use --add-data , it will pack the images in the exe file and the script directory will not be the same , so i am asking for another solution to change it automatically or if there is a function to do so. – Alaa ebrahim Aug 24 '22 at 09:25
  • Use `resource_path()` like in this [answer](https://stackoverflow.com/a/51061279/3589122). See also https://pyinstaller.org/en/stable/runtime-information.html#run-time-information – GordonAitchJay Aug 24 '22 at 16:31

0 Answers0