Pergunta

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?

Foi útil?

Solução

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)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top