第一种:
import winreg def get_desktop(): key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders',) return winreg.QueryValueEx(key, "Desktop")[0] print(get_desktop())
第二种:
#该方法在用户改变了桌面路径后,会失效 import os def GetDesktopPath(): return os.path.join(os.path.expanduser("~"), 'Desktop')