easygui fileopenbox:打开带有“.”的路径(例如 C:\Users\user\.atom)

easygui fileopenbox: open a path with a '.' (ex C:\Users\user\.atom)

我想用 easygui 打开一个文件对话框,但路径包含一个带有 . 的文件夹:C:\Users\user\.atom

myfile= easygui.fileopenbox(msg="Choose a file", default=r"C:\Users\user\.atom")

这将打开 C:\Users\user 而非 C:\Users\user\.atom

的对话框

我没有/不使用easygui,只是看了源代码。

easyguidefault 参数进行一些路径处理。该处理涉及 [Python]: os.path.split(path) ,它将路径分成两部分(最后一个路径分隔符之前和之后的内容(bkslash 或“\ “))。
因为“.atom”在最后一个“\”之后,它不被视为路径的一部分(事实上它包含一个“.”纯属巧合,与此无关。

要解决您的问题,请在您的路径中添加一个通配符,例如:

myfile = easygui.fileopenbox(msg="Choose a file", default=r"C:\Users\user\.atom\*")

另一个解决方案是用两个 \:

结束默认
r"C:\Users\user\.atom\"