I want to set my initialdir to a KNOWNFOLDERID like Documents or Desktop. Is this even possible? I tried like this, but instead it open up the directory of my python project.
from tkinter import *
from tkinter import filedialog
root = Tk()
root.filename = filedialog.askopenfilename(
initialdir="%USERPROFILE%/Documents",
title="get a file",
filetypes=((".jpg files", "*.jpg"), (".png files", "*.png"))
)
root.mainloop()
You can use pathlib's
homeif you just need the user's directory.To get the path of the documents folder use
This will work both on Windows and Unix based OS.
Alternatively you can use
expandvarsfrom os.path