这是可能的。
您可以通过以下方式引用此文件夹CLSID
键,即20D04FE0-3AEA-1069-A2D8-08002B30309D
并可以通过以下路径在注册表中查看:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}
所以试试这个:
import tkinter as tk
import tkinter.filedialog as filedialog
root = tk.Tk()
root.withdraw()
root.filename = filedialog.askopenfilename(initialdir='::{20D04FE0-3AEA-1069-A2D8-08002B30309D}',
title='Select file',
filetypes=(('text files', '*.txt'), ('all files', '*.*')))
或者,您可以通过以下方式到达此虚拟路径外壳快捷方式 https://ss64.com/nt/shell.html shell:MyComputerFolder
,这更有意义且更具可读性:
import tkinter as tk
import tkinter.filedialog as filedialog
root = tk.Tk()
root.withdraw()
root.filename = filedialog.askopenfilename(initialdir='shell:MyComputerFolder',
title='Select file',
filetypes=(('text files', '*.txt'), ('all files', '*.*')))