如果我不指定目录,Python Tkinter 应该使用默认目录
我有以下程序: https://i.sstatic.net/tgzxz.png 。现在,如果我按“下载位置”按钮,则应将歌曲下载到所选目录中,这可以很好地工作。但是,如果我不按按钮,则应使用我选择的目录,“默认目录”,然后将文件移至此“默认目录” 移动文件的“选择下载位置按钮”代码的
def select_download_location():
global destination_source_new
destination_source_new =
filedialog.askdirectory(initialdir=os.path.normpath(r'C:\Users\kevin\Music'))
代码下载位置:
filename_url = "y2meta.com"
format = ".mp3"
space = filename_url + " "
hyphen ="- "
quality_file_320 = " (320 kbps)"
backslash = "\\"
filename = '\\'+ space + hyphen +title+ quality_file_320 +format
# Location where the file is downloaded to
download_source = r'C:\Users\kevin\Downloads'
source = download_source + filename
# Location where the file should be moved to
destination = destination_source_new
# Move the file from the download folder to the destination folder
dest = shutil.move(source,destination)
I have the following program: https://i.sstatic.net/TgzXz.png. Now if I press the Download Location Button, then it should download the song to the chosen directory, this works perfectly. But if I don't press the button, then it should use a directory, which I chose, "a default directory" and move the file to this "default directory"
Code of the "Choose Download Location Button"
def select_download_location():
global destination_source_new
destination_source_new =
filedialog.askdirectory(initialdir=os.path.normpath(r'C:\Users\kevin\Music'))
Code of the moving file to download location:
filename_url = "y2meta.com"
format = ".mp3"
space = filename_url + " "
hyphen ="- "
quality_file_320 = " (320 kbps)"
backslash = "\\"
filename = '\\'+ space + hyphen +title+ quality_file_320 +format
# Location where the file is downloaded to
download_source = r'C:\Users\kevin\Downloads'
source = download_source + filename
# Location where the file should be moved to
destination = destination_source_new
# Move the file from the download folder to the destination folder
dest = shutil.move(source,destination)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按如下方式指定目的地,如果目的地没有更改,它将采用默认目的地。
输出:
you can assign destination as below and if destination doesn't changes it will take default destination.
Output: