'Python Tkinter should use default directory, if I don't specify the directory

I have the following program: https://i.stack.imgur.com/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)


Solution 1:[1]

you can assign destination as below and if destination doesn't changes it will take default destination.

destination_source_new = ''
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
target  = r'C:\Users\kevin\Music'
destination = destination_source_new if destination_source_new  != '' else target
# Move the file from the download folder to the destination folder
print(source)
print(destination)
dest = shutil.move(source, destination)

Output:

source= C:\Users\kevin\Downloads\y2meta.com - title (320 kbps).mp3
destination= C:\Users\kevin\Music

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1