如何在 python tkinter 中添加到 gui 应用程序的下载路径

How to add a download path to gui application in python tkinter

如何将此下载路径添加到我使用 python 制作的 tkinter 中的 GUI 应用程序?

downloads_path = str(Path.home() / "Downloads")

对此


    with open(f"{name}.mp4", "wb") as out:
        out.write(video_bytes)

因为您已经使用了 pathlib.Path class,您可以将 downloads_path 保留为类型 pathlib.Path 而不是 string:

downloads_path = Path.home() / "Downloads"

然后您可以在第二个代码块中使用它,如下所示:

with open(downloads_path/f"{name}.mp4", "wb") as out:
    out.write(video_bytes)

如果您仍想将 downloads_path 保留为字符串,则可以使用 os.path.join(...),如下所示:

import os

...

with open(os.path.join(downloads_path, f"{name}.mp4"), "wb") as out:
    out.write(video_bytes)