There is no "linking" of buttons to functions, nor callback functions.
To do what you're looking for, calling copy when you get a "Copy Button"event back from a Read.
I urge you to read through the docs to get an understanding how these calls to Button, etc, work. http://www.PySimpleGUI.org
Here's what I think you are looking for your code to do:
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", button_color=("white",
"green"), size=(6, 1)),sg.Exit(button_color=("white", "red"),
size=(6, 1))]]
window = sg.Window("Mass File Transfer").Layout(layout)
while True:
event, values = window.Read()
print(event, values)
if event in (None, 'Exit'):
break
if event == 'Copy':
copy(values[0], values[1])
Answer from Mike from PSG on Stack OverflowPySimpleGUI
docs.pysimplegui.com › en › latest › documentation › module › elements › button
Button - PySimpleGUI Documentation
A Dummy button is added to your layout by typing sg.DummyButton. These are special purpose buttons that will close a window without generating an event. Dummy buttons are used with Async Windows. These windows are not closed explicitly by your code. Instead, PySimpleGUI closes the window for ...
TutorialsPoint
tutorialspoint.com › pysimplegui › pysimplegui_button_element.htm
PySimpleGUI - Button Element
The FileBrowse button opens a file dialog from which a single file can be selected. In the following code, the path string of the selected file is displayed in the target Input bow in the same row. import PySimpleGUI as psg layout = [ [psg.Text('Select a file',font=('Arial Bold', 20), expand_x=True, justification='center')], [psg.Input(enable_events=True, key='-IN-',font=('Arial Bold', 12),expand_x=True), psg.FileBrowse()] ] window = psg.Window('FileChooser Demo', layout, size=(715,100)) while True: event, values = window.read() if event == psg.WIN_CLOSED or event == 'Exit': break window.close()
Videos
06:39
Image Button GUI App With Python PySimpleGUI - Tutorial 14 - YouTube
15:47
PySimpleGUI 2020 Part 12 - Menus (Menubar, Right Click Menu, ...
08:04
Python Calculator with GUI | PySimpleGUI | Texas Instruments DataMath ...
14:46
PySimpleGUI 2020 Part 7 - Button Targets (File, Calendar, Color ...
20:39
PySimpleGUI 2020 Part 10 - Generated Layouts. Writing code to create ...
ProgramCreek
programcreek.com › python › example › 116002 › PySimpleGUI.Button
Python Examples of PySimpleGUI.Button
Try this')], [sg.Text('Here come the good colors as defined by PySimpleGUI')], [sg.Text('Button Colors Using PySimpleGUI.BLUES')], [*[sg.Button('BLUES[{}]\n{}'.format(j, c), button_color=(sg.YELLOWS[0], c), size=s10) for j, c in enumerate(sg.BLUES)]], [sg.Text('_' * 100, size=(65, 1))], [sg.Text('Button Colors Using PySimpleGUI.PURPLES')], [*[sg.Button('PURPLES[{}]\n{}'.format(j, c), button_color=(sg.YELLOWS[0], c), size=s10) for j, c in enumerate(sg.PURPLES)]], [sg.Text('_' * 100, size=(65, 1))], [sg.Text('Button Colors Using PySimpleGUI.GREENS')], [*[sg.Button('GREENS[{}]\n{}'.format(j, c),
YouTube
youtube.com › coding is amazing
Python PySimpleGUI - Buttons and menu elements Tutorial #02 - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket · © 2025 Google LLC
Published August 21, 2022 Views 7K
PySimpleGUI
docs.pysimplegui.com › en › latest › documentation › module › elements › button_menu
ButtonMenu - PySimpleGUI Documentation
The ButtonMenu element produces a unique kind of effect. It's a button, that when clicked, shows you a menu. It's like clicking one of the top-level menu items on a MenuBar.
GitHub
github.com › PySimpleGUI › PySimpleGUI › blob › master › DemoPrograms › Demo_Button_Toggle.py
PySimpleGUI/DemoPrograms/Demo_Button_Toggle.py at master · PySimpleGUI/PySimpleGUI
You may not redistribute, modify or otherwise use PySimpleGUI or its contents except pursuant to the PySimpleGUI License Agreement. ... sg.Button('', image_data=toggle_btn_off, key='-TOGGLE-GRAPHIC-', button_color=(sg.theme_background_color(), sg.theme_background_color()), border_width=0)],
Author PySimpleGUI
GitHub
github.com › PySimpleGUI › PySimpleGUI › issues › 3412
[ Help Wanted ] Nice looking button graphics wanted.... · Issue #3412 · PySimpleGUI/PySimpleGUI
September 25, 2020 - Today a new Demo Program was released that shows a number of base64 buttons defined and in use in a program.
Author PySimpleGUI
PySimpleGUI
docs.pysimplegui.com › en › latest › cookbook › original › graphical_buttons
Replacing a Button with a Graphic - PySimpleGUI Documentation
In PySimpleGUI you can use PNG and GIF image files as buttons.
GitHub
github.com › PySimpleGUI › PySimpleGUI › issues › 5375
[Question] trying to find help on how to place buttons in different area of a window · Issue #5375 · PySimpleGUI/PySimpleGUI
April 17, 2022 - [x ] Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released · Im try to figure out how to place a buttons on a window in different places beside how it default to where they are listed or next to each other. As in tkinter you can use place() which let you use x,y an places the object to where ever.
Author Cyberfal1
PySimpleGUI
docs.pysimplegui.com › en › latest › cookbook › ecookbook › elements › toggle-button-super-simple
Toggle Button - PySimpleGUI Documentation
It's a simple way to get a toggle button in PySimpleGUI using the Button Element.
PySimpleGUI
docs.pysimplegui.com › en › latest › call_reference › tkinter › elements › pre_defined_buttons
Pre-Defined Buttons - PySimpleGUI Documentation
ColorChooserButton( button_text, target = (555666777, -1), image_filename = None, image_data = None, image_size = (None, None), image_subsample = None, tooltip = None, border_width = None, size = (None, None), s = (None, None), auto_size_button = None, button_color = None, disabled = False, font = None, bind_return_key = False, focus = False, pad = None, p = None, key = None, k = None, default_color = None, visible = True, metadata = None, expand_x = False, expand_y = False )
GitHub
github.com › PySimpleGUI › PySimpleGUI › blob › master › DemoPrograms › Demo_Buttons_Realtime.py
PySimpleGUI/DemoPrograms/Demo_Buttons_Realtime.py at master · PySimpleGUI/PySimpleGUI
April 17, 2022 - [sg.Text('Hold Down Button To Move')],
Author PySimpleGUI
iO Flood
ioflood.com › blog › pysimplegui
PySimpleGUI: Guide to Python GUI Development
February 7, 2024 - If the ‘Hello’ button is clicked, we print ‘Hello, World!’. The loop continues until the window is closed. This is just a basic introduction to PySimpleGUI. There’s so much more to learn about this powerful library, including how to add different types of widgets, handle events, and create complex layouts.
PySimpleGUI
docs.pysimplegui.com › en › latest › cookbook › original › menus
Menus - PySimpleGUI Documentation
When you click on a menu item, you get back a "button" with that menu item's text, just as you would had that text been on a button.
GitHub
github.com › PySimpleGUI › PySimpleGUI › issues › 3646
[ Question] How do I get the button (option) that the user chose in a popup · Issue #3646 · PySimpleGUI/PySimpleGUI
November 20, 2020 - Hi I want to ask a question How do I get the button (option) that the user chose in a popup I leave an example code · import PySimpleGUI as sg sg.theme('DarkAmber') # Keep things interesting for your users layout = [[sg.Text('Persistent window')], [sg.Button('Read'), sg.Exit()]] window = sg.Window('Window that stays open', layout) while True: # The Event Loop event, values = window.read() if event == sg.WIN_CLOSED or event == 'Exit': break if event == 'Read': sg.PopupOKCancel('PopupOKCancel') if event == 'ok': print('the user pressed the OK button') if event == 'Cancel': print('the user pressed the Cancel button') window.close()
Author shields1968
Mouse Vs Python
blog.pythonlibrary.org › home › pysimplegui - an intro to laying out elements
PySimpleGUI - An Intro to Laying Out Elements - Mouse Vs Python
January 25, 2022 - When you run this code, you will see the buttons aligned horizontally, with one next to the other going from left-to-right. Now you are ready to see how you can rewrite the code to create a vertical layout! To create a vertically oriented layout with PySimpleGUI, you need to make the layout ...