Trying out PySimpleGui for the first time, wanting to create an exec program that allows the user to either move or copy directories/files to the destination of their choice, but dont really understand how to link the action to the buttons.
My current program looks like this:
import PySimpleGUI as sg
import shutil, errno
src = ""
dest = ""
def copy(src, dest):
try:
shutil.copytree(src, dest)
except OSError as e:
# If the error was caused because the source wasn't a directory
if e.errno == errno.ENOTDIR:
shutil.copy(src, dest)
else:
print('Directory not copied. Error: %s' % e)
#Me testing out commands in PSG
layout = [[ sg.Text("Select path from source to
destination")],
[sg.Text("Source Folder", size=(15,1)), sg.InputText(src),
sg.FolderBrowse()],
[sg.Text("Destination Folder", size=(15,1)),
sg.InputText(dest), sg.FolderBrowse()],
[sg.Button("Transfer", button_color=("white", "blue"), size=
(6, 1)),sg.Button(copy, "Copy", button_color=("white",
"green"), size=(6, 1)),sg.Exit(button_color=("white", "red"),
size=(6, 1))]]
event = sg.Window("Mass File Transfer").Layout(layout).Read()
From what I am able to clearly understand, I would think that involving the copy command into the button's properties would link it to the command defined earlier in the code. I have src and dest blank as the inputs for src and dest and laid out with a browse folder extension added on for easier file management.