Search code examples
pythonoperating-systemtkintertk-toolkithome-directory

tkinter home directory


When calling the

 tkFileDialog.askopenfile()

method in tkinter, how do I set the default directory to the home directory of the user? Is there a way to do this independent of operating system, or is this something that the programmer has to deal with?


Solution

  • os.path.expanduser('~') should expand it out for you on most OSs (windows,unix)...

    In other words:

    home = os.path.expanduser('~')
    f = tkFileDialog.askopenfile(initialdir = home)