Search code examples
pythonvbaspss

Specify Input File in SPSS Statistics


In older versions of SPSS, one could ask for the path to a file using a syntax similar to this:

filename = GetFilePath("*.txt","txt", ,"Specify input file",0)

How can I achieve the same result using recent versions of SPSS, that rely on Python?


Solution

  • I found the answer. So similarly to how the VBA in .SBS script works, Python can use a library directly from SPSS to show a file input dialog.

    BEGIN PROGRAM.
    from Tkinter import Tk
    from tkFileDialog import askopenfilename
    
    Tk().withdraw()
    filename = askopenfilename()
    print(filename)
    END PROGRAM.