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()
python - Using PySimpleGui, how to get buttons to work? - Stack Overflow
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 unders... More on stackoverflow.com
[ Help Wanted ] Nice looking button graphics wanted....
Type of Issues (Enhancement, Error, Bug, Question) Enhancement PySimpleGUI Port and Version Ports = tkinter, Qt, WxPython (likely not going to be on the Web port initially) Description of Request Flat and Gradient Buttons I've been speak... More on github.com
[Question] trying to find help on how to place buttons in different area of a window
Type of Issue (Enhancement, Error, Bug, Question) question with buttons Operating System raspberry pi PySimpleGUI Port (tkinter, Qt, Wx, Web) tkinter Versions Version information can be obtained by calling sg.main_get_debug_data() Or you... More on github.com
python - PySimpleGUI call a function when pressing button - Stack Overflow
How can I call a function when I press the submit button? or any other button? ... I just added to my answer that you don't have to add an event loop. You can put the "if" statements right after your last line of code, the Read call. Thanks for marking the question as answered. ... The PySimpleGUI ... More on stackoverflow.com
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
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
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
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 › 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 › original › graphical_buttons
Replacing a Button with a Graphic - PySimpleGUI Documentation
In PySimpleGUI you can use PNG and GIF image files as buttons.
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.
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
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 )
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