Search code examples
pythonfinder

How to use Mac finder import image with Python executable


I already finished my project source code. The code is basically about analysis an image. However, I am currently using cv2.imread() to import the image to source code.

I am expecting that user can choose image from Mac finder after I convert the source code to executable.

Basically what I want is: When user open the executable, Mac finder will show up and user can choose image from it.

I really don't know what to do to achieve this.


Solution

  • You can use tkinter and file dialog to open a finder menu as follows:

    from tkinter import filedialog, Tk
    
    root = Tk()
    root.withdraw()
    
    path = filedialog.askopenfilename()