Question

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?

Was it helpful?

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top